opentk / GLWpfControl

A fast native control for OpenTK 4.x + 3.x on WPF.
MIT License
194 stars 48 forks source link

Dispose error on unitialized control #113

Open MikaelStalvik opened 1 year ago

MikaelStalvik commented 1 year ago

If the GLWpfControl cannot be initialized as described in this issue, an error will be thrown when the control is internally disposed:

OpenTK.Windowing.GraphicsLibraryFramework.GLFWException: You can only dispose windows on the main thread. The window needs to be disposed as it cannot safely be disposed in the finalizer. at OpenTK.Windowing.Desktop.NativeWindow.Dispose(System.Boolean disposing) at offset 54 at OpenTK.Windowing.Desktop.NativeWindow.Finalize()

This seems weird since the actual control is created, but not properly initialized, on the main thread.

NogginBops commented 1 year ago

Ok it seems like this is happening because after the exception is thrown in window creation the NativeWindow finalizer gets called and that isn't supposed to happen. Not sure if this issue is best fixed in GLWpfControl or in OpenTK itself, will have to think about that one. But basically we could catch the exception and dispose the window ourself in some way, but it might require changes in OpenTK to fully work.