From: José Fonseca Date: Wed, 24 Oct 2012 19:04:54 +0000 (+0100) Subject: Make code more robust against multiply bound CGL contexts. X-Git-Url: https://git.cworth.org/git?a=commitdiff_plain;h=b54d9bb5b355edfed7e443ef17f0dce5355c7575;p=apitrace Make code more robust against multiply bound CGL contexts. As it is allowed by the CGL API. --- diff --git a/retrace/glretrace.hpp b/retrace/glretrace.hpp index 572adec..95a6d75 100644 --- a/retrace/glretrace.hpp +++ b/retrace/glretrace.hpp @@ -41,10 +41,7 @@ struct Context { { } - ~Context() - { - delete wsContext; - } + ~Context(); glws::Context* wsContext; diff --git a/retrace/glretrace_cgl.cpp b/retrace/glretrace_cgl.cpp index 7ef1b4a..a075595 100644 --- a/retrace/glretrace_cgl.cpp +++ b/retrace/glretrace_cgl.cpp @@ -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); } } diff --git a/retrace/glretrace_ws.cpp b/retrace/glretrace_ws.cpp index 5ae908f..ac03fcc 100644 --- a/retrace/glretrace_ws.cpp +++ b/retrace/glretrace_ws.cpp @@ -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) {