MacOS: Clean up AglContext destruction code.

Implement INativeWindow.Close method.
This commit is contained in:
kanato 2009-11-14 21:33:07 +00:00
parent ed05d8e12c
commit 52e89c13b1
2 changed files with 23 additions and 16 deletions

View file

@ -358,6 +358,7 @@ namespace OpenTK.Platform.MacOS
#endregion #endregion
#region IDisposable Members #region IDisposable Members
~AglContext() ~AglContext()
{ {
Dispose(false); Dispose(false);
@ -374,25 +375,20 @@ namespace OpenTK.Platform.MacOS
return; return;
Debug.Print("Disposing of AGL context."); Debug.Print("Disposing of AGL context.");
try
{
throw new Exception();
}
catch (Exception e)
{
Debug.WriteLine(e.StackTrace);
}
Agl.aglSetCurrentContext(IntPtr.Zero); 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) if (Agl.aglDestroyContext(Handle.Handle) == true)
{ {
Handle = ContextHandle.Zero; Debug.Print("Context destruction completed successfully.");
return; Handle = ContextHandle.Zero;
return;
} }
// failed to destroy context. // failed to destroy context.

View file

@ -124,6 +124,8 @@ namespace OpenTK.Platform.MacOS
Debug.Print("Disposing of CarbonGLNative window."); Debug.Print("Disposing of CarbonGLNative window.");
API.DisposeWindow(window.WindowRef);
mIsDisposed = true; mIsDisposed = true;
mExists = false; mExists = false;
@ -136,6 +138,7 @@ namespace OpenTK.Platform.MacOS
} }
DisposeUPP(); DisposeUPP();
} }
~CarbonGLNative() ~CarbonGLNative()
@ -842,7 +845,15 @@ namespace OpenTK.Platform.MacOS
public void Close() public void Close()
{ {
throw new NotImplementedException(); CancelEventArgs e = new CancelEventArgs();
OnClosing(e);
if (e.Cancel)
return;
OnClosed();
Dispose();
} }
public WindowState WindowState public WindowState WindowState