mirror of
https://github.com/Ryujinx/Opentk.git
synced 2025-03-08 10:10:00 +00:00
Added workaround for wglMakeCurrent error 6
On some drivers and virtual machines, wglMakeCurrent may fail with a code 6 when first called. The suggested workaround is to call it in a loop until it succeeds. See https://www.opengl.org/discussion_boards/showthread.php/171058-nVidia-wglMakeCurrent()-multiple-threads
This commit is contained in:
parent
2e14ca59b2
commit
0ee72856e4
|
@ -1,4 +1,4 @@
|
||||||
#region --- License ---
|
#region --- License ---
|
||||||
/* Copyright (c) 2006, 2007 Stefanos Apostolopoulos
|
/* Copyright (c) 2006, 2007 Stefanos Apostolopoulos
|
||||||
* Contributions from Erik Ylvisaker
|
* Contributions from Erik Ylvisaker
|
||||||
* See license.txt for license info
|
* See license.txt for license info
|
||||||
|
@ -71,12 +71,29 @@ namespace OpenTK.Platform.Windows
|
||||||
ContextHandle temp_context = new ContextHandle(Wgl.Imports.CreateContext(window.DeviceContext));
|
ContextHandle temp_context = new ContextHandle(Wgl.Imports.CreateContext(window.DeviceContext));
|
||||||
if (temp_context != ContextHandle.Zero)
|
if (temp_context != ContextHandle.Zero)
|
||||||
{
|
{
|
||||||
bool success = Wgl.Imports.MakeCurrent(window.DeviceContext, temp_context.Handle);
|
// Make the context current.
|
||||||
if (!success)
|
// Note: on some video cards and on some virtual machines, wglMakeCurrent
|
||||||
Debug.Print("wglMakeCurrent failed with error: {0}", Marshal.GetLastWin32Error());
|
// may fail with an errorcode of 6 (INVALID_HANDLE). The suggested workaround
|
||||||
Wgl.LoadAll();
|
// is to call wglMakeCurrent in a loop until it succeeds.
|
||||||
|
// See https://www.opengl.org/discussion_boards/showthread.php/171058-nVidia-wglMakeCurrent()-multiple-threads
|
||||||
|
// Sigh...
|
||||||
|
for (int retry = 0; retry < 5; retry++)
|
||||||
|
{
|
||||||
|
bool success = Wgl.Imports.MakeCurrent(window.DeviceContext, temp_context.Handle);
|
||||||
|
if (!success)
|
||||||
|
{
|
||||||
|
Debug.Print("wglMakeCurrent failed with error: {0}. Retrying", Marshal.GetLastWin32Error());
|
||||||
|
System.Threading.Thread.Sleep(10);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// wglMakeCurrent succeeded, we are done here!
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Destroy temporary context
|
// Load wgl extensions and destroy temporary context
|
||||||
|
Wgl.LoadAll();
|
||||||
Wgl.Imports.MakeCurrent(IntPtr.Zero, IntPtr.Zero);
|
Wgl.Imports.MakeCurrent(IntPtr.Zero, IntPtr.Zero);
|
||||||
Wgl.Imports.DeleteContext(temp_context.Handle);
|
Wgl.Imports.DeleteContext(temp_context.Handle);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue