glx: Destroy the old context only after the new one has been bound
authorJeremy Huddleston <jeremyhu@apple.com>
Fri, 17 Jun 2011 19:28:05 +0000 (12:28 -0700)
committerJeremy Huddleston <jeremyhu@apple.com>
Mon, 20 Jun 2011 23:54:58 +0000 (16:54 -0700)
This fixes a regression introduced by 49d7e48b33264d94e30af6129c281b6acafa9427

Signed-off-by: Jeremy Huddleston <jeremyhu@apple.com>
src/glx/glxcurrent.c

index 9eb7d5ac546f6bc4935f00892bfb60b13efa6e19..0f39ee507373094018b1e35926cb3e4df31a3efe 100644 (file)
@@ -255,13 +255,6 @@ MakeContextCurrent(Display * dpy, GLXDrawable draw,
       if (--oldGC->thread_refcount == 0) {
         oldGC->vtable->unbind(oldGC, gc);
         oldGC->currentDpy = 0;
-
-        if (oldGC->xid == None && oldGC != gc) {
-           /* We are switching away from a context that was
-            * previously destroyed, so we need to free the memory
-            * for the old handle. */
-           oldGC->vtable->destroy(oldGC);
-        }
       }
    }
 
@@ -279,6 +272,13 @@ MakeContextCurrent(Display * dpy, GLXDrawable draw,
       __glXSetCurrentContextNull();
    }
 
+   if (oldGC->thread_refcount == 0 && oldGC != &dummyContext && oldGC->xid == None) {
+      /* We are switching away from a context that was
+       * previously destroyed, so we need to free the memory
+       * for the old handle. */
+      oldGC->vtable->destroy(oldGC);
+   }
+
    __glXUnlock();
 
    if (ret) {