Assert "leaving a context current"
antoinecla opened this issue · comments
antoinecla commented
Step to reproduce:
- On Visual Studio 2015
- Create new Windows Forms application, .NET 4.6.1
- Add reference to:
OpenGL.Net\OpenGL.Net.WinForms\bin\net461\Debug\OpenGL.Net.WinForms.dll OpenGL.Net.WInforms
- Open Form1
- Add
GlControl
- Build and run
Result:
On start, assert: "leaving a context current".
Clicking Ignore allows the application to run without other issues.
Stack trace:
OpenGL.Net.dll!OpenGL.DeviceContext.Dispose(bool disposing) Line 734 C#
OpenGL.Net.dll!OpenGL.DeviceContextEGL.Dispose(bool disposing) Line 1183 C#
OpenGL.Net.dll!OpenGL.DeviceContext.Dispose() Line 745 C#
OpenGL.Net.dll!OpenGL.Egl.Initialize() Line 149 C#
OpenGL.Net.dll!OpenGL.Egl.Egl() Line 54 C#
[Native to Managed Transition]
[Managed to Native Transition]
OpenGL.Net.dll!OpenGL.DeviceContext.DeviceContext() Line 43 C#
[Native to Managed Transition]
[Managed to Native Transition]
OpenGL.Net.WinForms.dll!OpenGL.GlControl.CreateDeviceContext(OpenGL.DevicePixelFormat controlReqFormat) Line 564 C#
OpenGL.Net.WinForms.dll!OpenGL.GlControl.CreateDeviceContext() Line 541 C#
OpenGL.Net.WinForms.dll!OpenGL.GlControl.OnHandleCreated(System.EventArgs e) Line 1106 C#
System.Windows.Forms.dll!System.Windows.Forms.Control.WmCreate(ref System.Windows.Forms.Message m) Unknown
System.Windows.Forms.dll!System.Windows.Forms.Control.WndProc(ref System.Windows.Forms.Message m) Unknown
System.Windows.Forms.dll!System.Windows.Forms.ScrollableControl.WndProc(ref System.Windows.Forms.Message m) Unknown
System.Windows.Forms.dll!System.Windows.Forms.ContainerControl.WndProc(ref System.Windows.Forms.Message m) Unknown
System.Windows.Forms.dll!System.Windows.Forms.UserControl.WndProc(ref System.Windows.Forms.Message m) Unknown
System.Windows.Forms.dll!System.Windows.Forms.Control.ControlNativeWindow.OnMessage(ref System.Windows.Forms.Message m) Unknown
System.Windows.Forms.dll!System.Windows.Forms.Control.ControlNativeWindow.WndProc(ref System.Windows.Forms.Message m) Unknown
System.Windows.Forms.dll!System.Windows.Forms.NativeWindow.DebuggableCallback(System.IntPtr hWnd, int msg, System.IntPtr wparam, System.IntPtr lparam) Unknown
[Native to Managed Transition]
[Managed to Native Transition]
System.Windows.Forms.dll!System.Windows.Forms.UnsafeNativeMethods.CreateWindowEx(int dwExStyle, string lpszClassName, string lpszWindowName, int style, int x, int y, int width, int height, System.Runtime.InteropServices.HandleRef hWndParent, System.Runtime.InteropServices.HandleRef hMenu, System.Runtime.InteropServices.HandleRef hInst, object pvParam) Unknown
System.Windows.Forms.dll!System.Windows.Forms.NativeWindow.CreateHandle(System.Windows.Forms.CreateParams cp) Unknown
System.Windows.Forms.dll!System.Windows.Forms.Control.CreateHandle() Unknown
System.Windows.Forms.dll!System.Windows.Forms.Control.CreateControl(bool fIgnoreVisible) Unknown
System.Windows.Forms.dll!System.Windows.Forms.Control.CreateControl(bool fIgnoreVisible) Unknown
System.Windows.Forms.dll!System.Windows.Forms.Control.CreateControl() Unknown
System.Windows.Forms.dll!System.Windows.Forms.Control.WmShowWindow(ref System.Windows.Forms.Message m) Unknown
System.Windows.Forms.dll!System.Windows.Forms.Control.WndProc(ref System.Windows.Forms.Message m) Unknown
System.Windows.Forms.dll!System.Windows.Forms.ScrollableControl.WndProc(ref System.Windows.Forms.Message m) Unknown
System.Windows.Forms.dll!System.Windows.Forms.Form.WmShowWindow(ref System.Windows.Forms.Message m) Unknown
System.Windows.Forms.dll!System.Windows.Forms.Form.WndProc(ref System.Windows.Forms.Message m) Unknown
System.Windows.Forms.dll!System.Windows.Forms.Control.ControlNativeWindow.OnMessage(ref System.Windows.Forms.Message m) Unknown
System.Windows.Forms.dll!System.Windows.Forms.Control.ControlNativeWindow.WndProc(ref System.Windows.Forms.Message m) Unknown
System.Windows.Forms.dll!System.Windows.Forms.NativeWindow.DebuggableCallback(System.IntPtr hWnd, int msg, System.IntPtr wparam, System.IntPtr lparam) Unknown
[Native to Managed Transition]
[Managed to Native Transition]
System.Windows.Forms.dll!System.Windows.Forms.Control.SetVisibleCore(bool value) Unknown
System.Windows.Forms.dll!System.Windows.Forms.Form.SetVisibleCore(bool value) Unknown
System.Windows.Forms.dll!System.Windows.Forms.Control.Visible.set(bool value) Unknown
System.Windows.Forms.dll!System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(int reason, System.Windows.Forms.ApplicationContext context) Unknown
System.Windows.Forms.dll!System.Windows.Forms.Application.ThreadContext.RunMessageLoop(int reason, System.Windows.Forms.ApplicationContext context) Unknown
System.Windows.Forms.dll!System.Windows.Forms.Application.Run(System.Windows.Forms.Form mainForm) Unknown
Test2.exe!Test2.Program.Main() Line 19 C#
Luca Piccioni commented
Good catch!
Indeed DeviceContext.GetCurrentContext()
is using WGL functions because it access to Egl.IsRequired
not being initialized yet.
The assertion is somewhat pedantic, but it's always a good idea to reset current GL context before device context disposition, isn't? On my system, calling wglGetCurrentContext
was returning zero, hiding the problem.