diff --git a/renderdoc/driver/gl/gl_initstate.cpp b/renderdoc/driver/gl/gl_initstate.cpp index e188b6dcc..3eedc8d51 100644 --- a/renderdoc/driver/gl/gl_initstate.cpp +++ b/renderdoc/driver/gl/gl_initstate.cpp @@ -567,14 +567,16 @@ bool GLResourceManager::Prepare_InitialState(GLResource res) ContextShareGroup *shareGroup = (ContextShareGroup *)res.ContextShareGroup; - m_Driver->m_ActiveContexts[Threading::GetCurrentID()] = shareGroup->m_BackDoor; - m_Driver->m_Platform.MakeContextCurrent(shareGroup->m_BackDoor); + if(m_Driver->m_Platform.MakeContextCurrent(shareGroup->m_BackDoor)) + { + m_Driver->m_ActiveContexts[Threading::GetCurrentID()] = shareGroup->m_BackDoor; - ContextPrepare_InitialState(res); + ContextPrepare_InitialState(res); - // restore the context - m_Driver->m_ActiveContexts[Threading::GetCurrentID()] = oldContextData; - m_Driver->m_Platform.MakeContextCurrent(oldContextData); + // restore the context + m_Driver->m_ActiveContexts[Threading::GetCurrentID()] = oldContextData; + m_Driver->m_Platform.MakeContextCurrent(oldContextData); + } } else { @@ -1813,18 +1815,19 @@ bool GLResourceManager::Serialise_InitialState(WriteSerialiser &ser, ResourceId GLWindowingData backdoor = ((ContextShareGroup *)res.ContextShareGroup)->m_BackDoor; - m_Driver->m_Platform.MakeContextCurrent(backdoor); + if(m_Driver->m_Platform.MakeContextCurrent(backdoor)) + { + m_Driver->m_ActiveContexts[Threading::GetCurrentID()] = backdoor; - m_Driver->m_ActiveContexts[Threading::GetCurrentID()] = backdoor; + bool success = Serialise_InitialState(ser, id, record, initial); - bool success = Serialise_InitialState(ser, id, record, initial); + // restore the context + m_Driver->m_ActiveContexts[Threading::GetCurrentID()] = oldContextData; - // restore the context - m_Driver->m_ActiveContexts[Threading::GetCurrentID()] = oldContextData; + m_Driver->m_Platform.MakeContextCurrent(oldContextData); - m_Driver->m_Platform.MakeContextCurrent(oldContextData); - - return success; + return success; + } } return Serialise_InitialState(ser, id, record, initial); diff --git a/renderdoc/driver/gl/gl_manager.cpp b/renderdoc/driver/gl/gl_manager.cpp index b50bc91a6..be6a025bb 100644 --- a/renderdoc/driver/gl/gl_manager.cpp +++ b/renderdoc/driver/gl/gl_manager.cpp @@ -145,12 +145,17 @@ bool GLResourceManager::ResourceTypeRelease(GLResource res) { ContextShareGroup *contextShareGroup = (ContextShareGroup *)res.ContextShareGroup; - m_Driver->m_Platform.MakeContextCurrent(contextShareGroup->m_BackDoor); + if(m_Driver->m_Platform.MakeContextCurrent(contextShareGroup->m_BackDoor)) + { + m_Driver->ReleaseResource(res); - m_Driver->ReleaseResource(res); - - // restore the context - m_Driver->m_Platform.MakeContextCurrent(m_Driver->m_ActiveContexts[Threading::GetCurrentID()]); + // restore the context + m_Driver->m_Platform.MakeContextCurrent(m_Driver->m_ActiveContexts[Threading::GetCurrentID()]); + } + else + { + m_Driver->QueueResourceRelease(res); + } } else { diff --git a/renderdoc/driver/gl/wgl_platform.cpp b/renderdoc/driver/gl/wgl_platform.cpp index 67871162e..885f01411 100644 --- a/renderdoc/driver/gl/wgl_platform.cpp +++ b/renderdoc/driver/gl/wgl_platform.cpp @@ -45,6 +45,25 @@ class WGLPlatform : public GLPlatform if(!WGL.wglCreateContextAttribsARB) return ret; + // the reason we have to create an entire window and DC is because the share DC (and window) + // can be destroyed after we make a clone, which causes the DC (and window) we hold on to, + // to become invalid. + if(!RegisterClass()) + return ret; + + HWND wnd = + CreateWindowW(WINDOW_CLASS_NAME, L"", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, + CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, GetModuleHandle(NULL), NULL); + + HDC dc = GetDC(wnd); + + int pf = GetPixelFormat(share.DC); + + PIXELFORMATDESCRIPTOR pfd; + DescribePixelFormat(share.DC, pf, sizeof(PIXELFORMATDESCRIPTOR), &pfd); + + SetPixelFormat(dc, pf, &pfd); + const int attribs[] = { WGL_CONTEXT_MAJOR_VERSION_ARB, 3, @@ -58,7 +77,13 @@ class WGLPlatform : public GLPlatform 0, }; - ret.ctx = WGL.wglCreateContextAttribsARB(share.DC, share.ctx, attribs); + HGLRC rc = WGL.wglCreateContextAttribsARB(dc, share.ctx, attribs); + + ShowWindow(wnd, SW_HIDE); + + ret.wnd = wnd; + ret.DC = dc; + ret.ctx = rc; return ret; } @@ -66,7 +91,11 @@ class WGLPlatform : public GLPlatform void DeleteClonedContext(GLWindowingData context) { if(context.ctx && WGL.wglDeleteContext) + { WGL.wglDeleteContext(context.ctx); + ::ReleaseDC(context.wnd, context.DC); + ::DestroyWindow(context.wnd); + } } void DeleteReplayContext(GLWindowingData context)