diff --git a/renderdoc/driver/gl/wgl_hooks.cpp b/renderdoc/driver/gl/wgl_hooks.cpp index 21b901182..df03e886f 100644 --- a/renderdoc/driver/gl/wgl_hooks.cpp +++ b/renderdoc/driver/gl/wgl_hooks.cpp @@ -101,7 +101,15 @@ void WGLHook::PopulateFromContext(HDC dc, HGLRC rc) }); // restore DC/context - WGL.wglMakeCurrent(prevDC, prevContext); + if(!WGL.wglMakeCurrent(prevDC, prevContext)) + { + RDCWARN( + "Couldn't restore prev context %p with prev DC %p - possibly stale. Using new DC %p to " + "ensure context is rebound properly", + prevContext, prevDC, dc); + + WGL.wglMakeCurrent(dc, prevContext); + } } } diff --git a/renderdoc/driver/gl/wgl_platform.cpp b/renderdoc/driver/gl/wgl_platform.cpp index 752fa1c96..173867206 100644 --- a/renderdoc/driver/gl/wgl_platform.cpp +++ b/renderdoc/driver/gl/wgl_platform.cpp @@ -70,10 +70,16 @@ class WGLPlatform : public GLPlatform virtual void PopChildContext(GLWindowingData existing, GLWindowingData newChild, GLWindowingData saved) { - MakeContextCurrent(saved); - // release the DC now, if we didn't use our own because theirs was invalid - if(saved.DC != newChild.DC) - ::ReleaseDC(saved.wnd, saved.DC); + // if possible we want to use the existing DC so that we have a valid DC for further work (the + // cloned one we're making is going to be destroyed). First try to rebind the existing as-is, + // and only if that fails - e.g. due to a stale DC - use our cloned one to rebind the context + if(!MakeContextCurrent(existing)) + { + MakeContextCurrent(saved); + // release the DC now, if we didn't use our own because theirs was invalid + if(saved.DC != newChild.DC) + ::ReleaseDC(saved.wnd, saved.DC); + } } GLWindowingData CloneTemporaryContext(GLWindowingData share) {