opentk / GLControl

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

OpenTK.WinForms (4.0.0-pre.6) works fine with OpenTK 4.7.1 but not with 4.7.2 #25

Closed MarcioAB closed 2 years ago

MarcioAB commented 2 years ago

To reproduce the problem:

(1) Create a WinForms project and add 2 NuGet packages: OpenTK.WinForms (4.0.0-pre.6) and OpenTK (4.7.1). (2) Add GLControl in the Form. It works fine. (3) Upgrade OpenTK (4.7.1) to OpenTK (4.7.2) and the GLControl will throw the exception bellow. (4) Downgrade to 4.7.1 and the control will be OK again.

OpenTK.WindowingGraphicsLibraryFramework.GLFWException: GLFW can only be called from the main thread! at OpenTK.Windowing.Desktop.GLFWProvider.EnsureInitialized() in C:\Users\juliuDocuments\GitHub\opentk\src\OpenTK.WindowingDesktop\GLFWProvider.cs:line 75 at OpenTK.Windowing.Desktop.NativeWindowSettings..ctor() in C:\Users\juliuDocuments\GitHub\opentk\src\OpenTK.WindowingDesktop\NativeWindowSettings.cs:line 35 at OpenTK.Winforms.GLControlSettings.ToNativeWindowSettings() in E:\dev\GLControl\OpenTK.WinForms\GLControlSettings.cs:line 121 at OpenTK.Winforms.GLControl.OnHandleCreated(EventArgs e) in E:\dev\GLControl\OpenTK.WinForms\GLControl.cs:line 228 at System.Windows.Forms.Control.WmCreate(Message& m) at System.Windows.Forms.Control.WndProc(Message& m) at Microsoft.DotNet.DesignTools.Designers.ControlDesigner.WndProc(Message& m) at Microsoft.DotNet.DesignTools.Designers.ControlDesigner.DesignerWindowTarget.OnMessage(Message& m)

NogginBops commented 2 years ago

A workaround for this is setting GLFWProvider.CheckMainThread = false in the static ctor of a subclass control of GLControl which will guarantee that the property is set to false before the designer code decides to call these functions. I have a fix ready in #26 , but it might be a few days before I can release the next version of this control.