framebuffers: cogl_offscreen_new_to_texture should take a ref on the texture
authorRobert Bragg <robert@linux.intel.com>
Wed, 25 Nov 2009 14:26:32 +0000 (14:26 +0000)
committerRobert Bragg <robert@linux.intel.com>
Fri, 8 Jan 2010 20:42:35 +0000 (20:42 +0000)
We weren't taking a reference on the texture to be used as the color buffer
for offscreen rendering, so it was possible to free the texture leaving the
framebuffer in an inconsistent state.

clutter/cogl/cogl/cogl-framebuffer-private.h
clutter/cogl/cogl/cogl-framebuffer.c

index eb94c6f..946adfe 100644 (file)
@@ -57,6 +57,7 @@ typedef struct _CoglOffscreen
   CoglFramebuffer  _parent;
   GLuint          fbo_handle;
   GLuint          gl_stencil_handle;
+  CoglHandle      texture;
 } CoglOffscreen;
 
 #define COGL_OFFSCREEN(X) ((CoglOffscreen *)(X))
index 585b676..a34eaaa 100644 (file)
@@ -339,6 +339,7 @@ cogl_offscreen_new_to_texture (CoglHandle texhandle)
 
   offscreen->fbo_handle         = fbo_gl_handle;
   offscreen->gl_stencil_handle  = gl_stencil_handle;
+  offscreen->texture            = cogl_handle_ref (texhandle);
 
   /* XXX: Can we get a away with removing this? It wasn't documented, and most
    * users of the API are hopefully setting up the modelview from scratch
@@ -362,6 +363,8 @@ _cogl_offscreen_free (CoglOffscreen *offscreen)
 
   if (offscreen->gl_stencil_handle)
     GE (glDeleteRenderbuffers (1, &offscreen->gl_stencil_handle));
+  if (offscreen->texture != COGL_INVALID_HANDLE)
+    cogl_handle_unref (offscreen->texture);
   GE (glDeleteFramebuffers (1, &offscreen->fbo_handle));
   g_free (offscreen);
 }