From 1e3f4f62e090ae0e93f18c7e45febeacbde20dc1 Mon Sep 17 00:00:00 2001 From: Robert Bragg Date: Fri, 27 May 2011 12:21:26 +0100 Subject: [PATCH] framebuffer: validate width/height in _set_viewport This validates that the viewport width and height arguments are positive values in _cogl_framebuffer_set_viewport. In addition, just before calling glViewport we also assert that something else hasn't gone amiss and that the internal viewport width/height values we track are still positive before passing to glViewport which generates an error for negative values. --- cogl/cogl-framebuffer.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/cogl/cogl-framebuffer.c b/cogl/cogl-framebuffer.c index efe010e4c..ac2244d16 100644 --- a/cogl/cogl-framebuffer.c +++ b/cogl/cogl-framebuffer.c @@ -513,6 +513,8 @@ _cogl_framebuffer_set_viewport (CoglFramebuffer *framebuffer, float width, float height) { + g_return_if_fail (width > 0 && height > 0); + if (framebuffer->viewport_x == x && framebuffer->viewport_y == y && framebuffer->viewport_width == width && @@ -976,8 +978,10 @@ _cogl_onscreen_new (void) ctx, COGL_FRAMEBUFFER_TYPE_ONSCREEN, COGL_PIXEL_FORMAT_RGBA_8888_PRE, - 0xdeadbeef, /* width */ - 0xdeadbeef); /* height */ + 0x1eadbeef, /* width */ + 0x1eadbeef); /* height */ + /* NB: make sure to pass positive width/height numbers here + * because otherwise we'll hit input validation assertions!*/ COGL_FRAMEBUFFER (onscreen)->allocated = TRUE; @@ -1413,9 +1417,8 @@ _cogl_framebuffer_flush_state (CoglFramebuffer *draw_buffer, { float gl_viewport_y; - if (draw_buffer->viewport_width < 0 - || draw_buffer->viewport_height < 0) - return; + g_assert (draw_buffer->viewport_width >=0 && + draw_buffer->viewport_height >=0); /* Convert the Cogl viewport y offset to an OpenGL viewport y offset * NB: OpenGL defines its window and viewport origins to be bottom