diff --git a/src/OpenTK/OpenTK.csproj b/src/OpenTK/OpenTK.csproj index 93e68005..bf4af5e4 100644 --- a/src/OpenTK/OpenTK.csproj +++ b/src/OpenTK/OpenTK.csproj @@ -137,6 +137,7 @@ + diff --git a/src/OpenTK/Platform/MacOS/Cocoa/NSAutoreleasePool.cs b/src/OpenTK/Platform/MacOS/Cocoa/NSAutoreleasePool.cs new file mode 100644 index 00000000..e6ba6c42 --- /dev/null +++ b/src/OpenTK/Platform/MacOS/Cocoa/NSAutoreleasePool.cs @@ -0,0 +1,34 @@ +using System; + +namespace OpenTK.Platform.MacOS +{ + /// + /// The class is a wrapper around the native objective-C NSAutoreleasePool. + /// In particular, this construct mimics the usage of an @autorelease block and can be used in much the same way, + /// only with a C# using block instead. + /// + public sealed class NSAutoreleasePool : IDisposable + { + private readonly IntPtr _autoreleasePool; + + /// + /// Allocates and initializes a new . + /// + public NSAutoreleasePool() + { + var uninitializedPool = Cocoa.SendIntPtr(Class.NSAutoreleasePool, Selector.Alloc); + _autoreleasePool = Cocoa.SendIntPtr(uninitializedPool, Selector.Init); + } + + /// + /// Disposes of the instance, draining it. + /// + public void Dispose() + { + if (_autoreleasePool != IntPtr.Zero) + { + Cocoa.SendVoid(_autoreleasePool, Selector.Get("drain")); + } + } + } +} \ No newline at end of file diff --git a/src/OpenTK/Platform/MacOS/CocoaContext.cs b/src/OpenTK/Platform/MacOS/CocoaContext.cs index 485713fa..eaae8324 100644 --- a/src/OpenTK/Platform/MacOS/CocoaContext.cs +++ b/src/OpenTK/Platform/MacOS/CocoaContext.cs @@ -345,12 +345,16 @@ namespace OpenTK return; } - if (IsCurrent) + using (var pool = new NSAutoreleasePool()) { - Cocoa.SendVoid(NSOpenGLContext, Selector.Get("clearCurrentContext")); + if (IsCurrent) + { + Cocoa.SendVoid(NSOpenGLContext, Selector.Get("clearCurrentContext")); + } + + Cocoa.SendVoid(Handle.Handle, Selector.Get("clearDrawable")); + Cocoa.SendVoid(Handle.Handle, Selector.Get("release")); } - Cocoa.SendVoid(Handle.Handle, Selector.Get("clearDrawable")); - Cocoa.SendVoid(Handle.Handle, Selector.Get("release")); Handle = ContextHandle.Zero; diff --git a/src/OpenTK/Platform/MacOS/CocoaNativeWindow.cs b/src/OpenTK/Platform/MacOS/CocoaNativeWindow.cs index 72ae5c00..5ec5fe93 100644 --- a/src/OpenTK/Platform/MacOS/CocoaNativeWindow.cs +++ b/src/OpenTK/Platform/MacOS/CocoaNativeWindow.cs @@ -137,6 +137,7 @@ namespace OpenTK.Platform.MacOS } private CocoaWindowInfo windowInfo; + private IntPtr windowClass; private IntPtr trackingArea; private IntPtr current_icon_handle;