opentk / GLControl

WinForms control for OpenTK 4.x.
https://opentk.net
Other
54 stars 24 forks source link

GLControl.OnHandleCreated exception #12

Closed dowdybrown closed 2 years ago

dowdybrown commented 3 years ago

I have a large WinForms application that I am converting to .Net 5. It was running fine using .Net Framework 4.8 and OpenTK 3. However, using NuGet OpenTK.WinForms 4.0.0-pre.6, the application crashes sometimes when creating an MDI window with a GLControl on it. From the stack trace, you can see that the crash is happening when the control is created, not when I am calling MakeCurrent myself. When I say some "sometimes", I would say 25-50% of the time it crashes, as if there is some race condition behind the scenes . The MDI windows are being created using DockPanelSuite 3.1.0.

Unhandled Exception: OpenTK.Windowing.GraphicsLibraryFramework.GLFWException: WGL: Failed to make context current: The handle is invalid. 
   at OpenTK.Windowing.Desktop.GLFWProvider.<>c.<.cctor>b__5_0(ErrorCode errorCode, String description)
   at OpenTK.Windowing.GraphicsLibraryFramework.GLFWNative.glfwCreateWindow(Int32 width, Int32 height, Byte* title, Monitor* monitor, Window* share)
   at OpenTK.Windowing.GraphicsLibraryFramework.GLFW.CreateWindow(Int32 width, Int32 height, String title, Monitor* monitor, Window* share)
   at OpenTK.Windowing.Desktop.NativeWindow..ctor(NativeWindowSettings settings)
   at OpenTK.WinForms.GLControl.CreateNativeWindow(NativeWindowSettings nativeWindowSettings)
   at OpenTK.WinForms.GLControl.OnHandleCreated(EventArgs e)
   at System.Windows.Forms.Control.WmCreate(Message& m)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, WM msg, IntPtr wparam, IntPtr lparam)
NogginBops commented 2 years ago

Can you tell me anything more about this? What OS are you running? Are you able to create a repro?

seanofw commented 2 years ago

Is the GLControl the actual MDI child-form container itself, or is it a child of the child-form container? I would expect the former to fail pretty badly, given how weird MDI is, but the latter should probably work. A minimal test case to reproduce this issue would be helpful.

seanofw commented 2 years ago

Closing this issue due to inactivity.