From e76983ef18d3b8c53ad8cb055dddcfa69d8d4ed2 Mon Sep 17 00:00:00 2001 From: Jjp137 Date: Fri, 19 Feb 2016 18:43:46 -0800 Subject: [PATCH] Fix BadWindow errors that occurred when closing an X11 window. This commit is based on OpenTK's fix in: https://github.com/opentk/opentk/commit/ec31675fc87883cb81c4df3498385a7fe54eae09 ...and was adapted for ClassicalSharp's modified OpenTK code. This also fixes options not being saved on Linux when the client or launcher closes, at least on Debian Jessie. The default error handler for Xlib is to print a message explaining the error to the console and then call exit(1). If that happens, the Options.Save() calls in Game.Dispose() and LauncherWindow.Run() are never reached. --- OpenTK/Platform/X11/X11GLNative.cs | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/OpenTK/Platform/X11/X11GLNative.cs b/OpenTK/Platform/X11/X11GLNative.cs index d87eb34ba..77ad3e642 100644 --- a/OpenTK/Platform/X11/X11GLNative.cs +++ b/OpenTK/Platform/X11/X11GLNative.cs @@ -326,8 +326,10 @@ namespace OpenTK.Platform.X11 { if (!ce.Cancel) { isExiting = true; - Debug.Print("Destroying window."); - API.XDestroyWindow(window.Display, window.WindowHandle); + + DestroyWindow(); + if (Closed != null) + Closed(this, EventArgs.Empty); } } break; @@ -335,8 +337,6 @@ namespace OpenTK.Platform.X11 { Debug.Print("Window destroyed"); exists = false; - if (Closed != null) - Closed(this, EventArgs.Empty); break; case XEventName.ConfigureNotify: @@ -766,7 +766,9 @@ namespace OpenTK.Platform.X11 { public void DestroyWindow() { Debug.Print("X11GLNative shutdown sequence initiated."); + API.XSync(window.Display, true); API.XDestroyWindow(window.Display, window.WindowHandle); + exists = false; } public Point PointToClient(Point point) { @@ -793,10 +795,7 @@ namespace OpenTK.Platform.X11 { if (manuallyCalled) { if (window != null && window.WindowHandle != IntPtr.Zero) { if (Exists) { - API.XDestroyWindow(window.Display, window.WindowHandle); - - while (Exists) - ProcessEvents(); + DestroyWindow(); } window.Dispose(); window = null;