[cogl] cogl-winsys: Fix freeing a CoglOnscreen



commit 463603f1a09d3eabe68b69659a4f7e10840515e1
Author: Neil Roberts <neil linux intel com>
Date:   Tue May 10 20:23:39 2011 +0100

    cogl-winsys: Fix freeing a CoglOnscreen
    
    All of the winsys backends didn't handle cleaning up the CoglOnscreen
    properly so that they would assert in cogl_onscreen_free because the
    winsys pointer is never freed. They also didn't cope if deinit is
    called before init (which will be the case if an onscreen is created
    and freed without being allocated).

 cogl/winsys/cogl-winsys-egl.c |    7 +++++++
 cogl/winsys/cogl-winsys-glx.c |    7 +++++++
 cogl/winsys/cogl-winsys-wgl.c |    7 +++++++
 3 files changed, 21 insertions(+), 0 deletions(-)
---
diff --git a/cogl/winsys/cogl-winsys-egl.c b/cogl/winsys/cogl-winsys-egl.c
index c7d6691..2533d69 100644
--- a/cogl/winsys/cogl-winsys-egl.c
+++ b/cogl/winsys/cogl-winsys-egl.c
@@ -1267,6 +1267,10 @@ _cogl_winsys_onscreen_deinit (CoglOnscreen *onscreen)
   CoglRendererEGL *egl_renderer = context->display->renderer->winsys;
   CoglOnscreenEGL *egl_onscreen = onscreen->winsys;
 
+  /* If we never successfully allocated then there's nothing to do */
+  if (egl_onscreen == NULL)
+    return;
+
   if (egl_onscreen->egl_surface != EGL_NO_SURFACE)
     {
       if (eglDestroySurface (egl_renderer->edpy, egl_onscreen->egl_surface)
@@ -1309,6 +1313,9 @@ _cogl_winsys_onscreen_deinit (CoglOnscreen *onscreen)
       egl_onscreen->wayland_surface = NULL;
     }
 #endif
+
+  g_slice_free (CoglOnscreenEGL, onscreen->winsys);
+  onscreen->winsys = NULL;
 }
 
 static void
diff --git a/cogl/winsys/cogl-winsys-glx.c b/cogl/winsys/cogl-winsys-glx.c
index 0aafcac..424910d 100644
--- a/cogl/winsys/cogl-winsys-glx.c
+++ b/cogl/winsys/cogl-winsys-glx.c
@@ -878,6 +878,10 @@ _cogl_winsys_onscreen_deinit (CoglOnscreen *onscreen)
   CoglOnscreenXlib *xlib_onscreen = onscreen->winsys;
   CoglOnscreenGLX *glx_onscreen = onscreen->winsys;
 
+  /* If we never successfully allocated then there's nothing to do */
+  if (glx_onscreen == NULL)
+    return;
+
   _cogl_xlib_trap_errors (&old_state);
 
   if (glx_onscreen->glxwin != None)
@@ -897,6 +901,9 @@ _cogl_winsys_onscreen_deinit (CoglOnscreen *onscreen)
   XSync (xlib_renderer->xdpy, False);
 
   _cogl_xlib_untrap_errors (&old_state);
+
+  g_slice_free (CoglOnscreenGLX, onscreen->winsys);
+  onscreen->winsys = NULL;
 }
 
 static void
diff --git a/cogl/winsys/cogl-winsys-wgl.c b/cogl/winsys/cogl-winsys-wgl.c
index 1cd81b6..8c2cb7e 100644
--- a/cogl/winsys/cogl-winsys-wgl.c
+++ b/cogl/winsys/cogl-winsys-wgl.c
@@ -654,6 +654,10 @@ _cogl_winsys_onscreen_deinit (CoglOnscreen *onscreen)
   CoglOnscreenWin32 *win32_onscreen = onscreen->winsys;
   CoglOnscreenWgl *wgl_onscreen = onscreen->winsys;
 
+  /* If we never successfully allocated then there's nothing to do */
+  if (wgl_onscreen == NULL)
+    return;
+
   if (wgl_onscreen->client_dc)
     {
       if (wgl_context->current_dc == wgl_onscreen->client_dc)
@@ -669,6 +673,9 @@ _cogl_winsys_onscreen_deinit (CoglOnscreen *onscreen)
       SetWindowLongPtrW (win32_onscreen->hwnd, 0, (LONG_PTR) 0);
       DestroyWindow (win32_onscreen->hwnd);
     }
+
+  g_slice_free (CoglOnscreenWgl, onscreen->winsys);
+  onscreen->winsys = NULL;
 }
 
 static gboolean



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]