]> git.cworth.org Git - apitrace/commitdiff
Make code more robust against multiply bound CGL contexts.
authorJosé Fonseca <jose.r.fonseca@gmail.com>
Wed, 24 Oct 2012 19:04:54 +0000 (20:04 +0100)
committerJosé Fonseca <jose.r.fonseca@gmail.com>
Wed, 24 Oct 2012 19:04:54 +0000 (20:04 +0100)
As it is allowed by the CGL API.

retrace/glretrace.hpp
retrace/glretrace_cgl.cpp
retrace/glretrace_ws.cpp

index 572adec34679118192f96e5eb682e20d10390a55..95a6d7596df230e8dd059194c493bbf58055cad3 100644 (file)
@@ -41,10 +41,7 @@ struct Context {
     {
     }
 
-    ~Context()
-    {
-        delete wsContext;
-    }
+    ~Context();
 
     glws::Context* wsContext;
 
index 7ef1b4a3de18481c5988e11822063d7bb0f24745..a0755953b3a52059e35f9d4e0ff9447cba878305 100644 (file)
@@ -239,13 +239,18 @@ static void retrace_CGLFlushDrawable(trace::Call &call) {
     Context *context = getContext(ctx);
 
     if (context) {
-        if (retrace::doubleBuffer) {
-            context->drawable->swapBuffers();
+        if (context->drawable) {
+            if (retrace::doubleBuffer) {
+                context->drawable->swapBuffers();
+            } else {
+                glFlush();
+            }
+            frame_complete(call);
         } else {
-            glFlush();
+            if (retrace::debug) {
+                retrace::warning(call) << "context has no drawable\n";
+            }
         }
-
-        frame_complete(call);
     }
 }
 
index 5ae908fc6c75a3cfffee7fb1d33077f65b090c95..ac03fcc97de6d56390f807a3b1661e6571d489c1 100644 (file)
@@ -122,6 +122,15 @@ createContext(Context *shareContext) {
 }
 
 
+Context::~Context()
+{
+    //assert(this != getCurrentContext());
+    if (this != getCurrentContext()) {
+        delete wsContext;
+    }
+}
+
+
 static thread_specific Context *
 currentContextPtr;
 
@@ -153,9 +162,6 @@ makeCurrent(trace::Call &call, glws::Drawable *drawable, Context *context)
         return false;
     }
 
-    if (currentContext) {
-        currentContext->drawable = NULL;
-    }
     currentContextPtr = context;
 
     if (drawable && context) {