Try to rebind user DC first when pushing/popping GL contexts. Refs #2361

* In the old codepath for a valid existing window we'd create a cloned DC and
  use that to pop with. However that DC is then released so we have created the
  'stale DC' situation. This can cause problems with subsequent context
  activations when we try to push/pop to populate GL hooks and fail to pop
  properly as the queried DC is invalid.
This commit is contained in:
baldurk
2021-09-14 17:54:48 +01:00
parent 2752008d13
commit 3d785b9b68
2 changed files with 19 additions and 5 deletions
+9 -1
View File
@@ -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);
}
}
}
+10 -4
View File
@@ -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)
{