diff --git a/Source/OpenTK/Platform/MacOS/AglContext.cs b/Source/OpenTK/Platform/MacOS/AglContext.cs index c2bf34e9..f57e8d7c 100644 --- a/Source/OpenTK/Platform/MacOS/AglContext.cs +++ b/Source/OpenTK/Platform/MacOS/AglContext.cs @@ -358,6 +358,7 @@ namespace OpenTK.Platform.MacOS #endregion #region IDisposable Members + ~AglContext() { Dispose(false); @@ -374,25 +375,20 @@ namespace OpenTK.Platform.MacOS return; Debug.Print("Disposing of AGL context."); - - try - { - throw new Exception(); - } - catch (Exception e) - { - Debug.WriteLine(e.StackTrace); - } - Agl.aglSetCurrentContext(IntPtr.Zero); - Agl.aglSetDrawable(Handle.Handle, IntPtr.Zero); - - Debug.Print("Set drawable to null for context {0}.", Handle.Handle); + + //Debug.Print("Setting drawable to null for context {0}.", Handle.Handle); + //Agl.aglSetDrawable(Handle.Handle, IntPtr.Zero); + // I do not know MacOS allows us to destroy a context from a separate thread, + // like the finalizer thread. It's untested, but worst case is probably + // an exception on application exit, which would be logged to the console. + Debug.Print("Destroying context"); if (Agl.aglDestroyContext(Handle.Handle) == true) { - Handle = ContextHandle.Zero; - return; + Debug.Print("Context destruction completed successfully."); + Handle = ContextHandle.Zero; + return; } // failed to destroy context. diff --git a/Source/OpenTK/Platform/MacOS/CarbonGLNative.cs b/Source/OpenTK/Platform/MacOS/CarbonGLNative.cs index 7cca609a..f1899bdb 100644 --- a/Source/OpenTK/Platform/MacOS/CarbonGLNative.cs +++ b/Source/OpenTK/Platform/MacOS/CarbonGLNative.cs @@ -124,6 +124,8 @@ namespace OpenTK.Platform.MacOS Debug.Print("Disposing of CarbonGLNative window."); + API.DisposeWindow(window.WindowRef); + mIsDisposed = true; mExists = false; @@ -136,6 +138,7 @@ namespace OpenTK.Platform.MacOS } DisposeUPP(); + } ~CarbonGLNative() @@ -842,7 +845,15 @@ namespace OpenTK.Platform.MacOS public void Close() { - throw new NotImplementedException(); + CancelEventArgs e = new CancelEventArgs(); + OnClosing(e); + + if (e.Cancel) + return; + + OnClosed(); + + Dispose(); } public WindowState WindowState