-
Notifications
You must be signed in to change notification settings - Fork 58
Description
The view containing my GlWpfControl throws the error
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.'
in DXGLContext.cs at GlfwWindow?.Dispose(); in the Dispose() method when navigating views in my application. I am not closing any windows and my application keeps running.
I tried to keep it on the main thread with a Dispatcher call explicitly calling out the Dispose() method on MyGlWpfControl.
protected void OnClosed(object o, RoutedEventArgs e)
{
Application.Current.Dispatcher.Invoke(() =>
{
MyGlWpfControl.Render -= OnRender;
MyGlWpfControl.Dispose();
});
}
but to no effect. Removing the OnClosed() method gives the same outcome.
Once the view is changed I believe that the garbage collector frees the resource on some thread other than the main thread.
I assume there is a good reason to dispose the window on the main thread but don't really know what that is right now.
What is the recommended approach to dispose a GlWpfControl while my application is running?