[Mac] Correctly release mach port
authorthefiddler <stapostol@gmail.com>
Wed, 23 Jul 2014 21:21:04 +0000 (23:21 +0200)
committerthefiddler <stapostol@gmail.com>
Wed, 23 Jul 2014 21:21:04 +0000 (23:21 +0200)
The event tap is released automatically along with the mach port. Fixes
crash on shutdown.

Source/OpenTK/Platform/MacOS/HIDInput.cs
Source/OpenTK/Platform/MacOS/Quartz/CoreFoundation.cs

index e2014c4..4c3e454 100755 (executable)
@@ -1756,13 +1756,11 @@ namespace OpenTK.Platform.MacOS
             {
                 if (manual)
                 {
-                    if (MouseEventTap != IntPtr.Zero)
-                    {
-                        CF.CFRelease(MouseEventTap);
-                        MouseEventTap = IntPtr.Zero;
-                    }
                     if (MouseEventTapSource != IntPtr.Zero)
                     {
+                        // Note: releasing the mach port (tap source)
+                        // automatically releases the event tap.
+                        CF.RunLoopRemoveSource(RunLoop, MouseEventTapSource, CF.RunLoopModeDefault);
                         CF.CFRelease(MouseEventTapSource);
                         MouseEventTapSource = IntPtr.Zero;
                     }
index 262fd7f..a11b9b9 100644 (file)
@@ -233,5 +233,11 @@ namespace OpenTK.Platform.MacOS.Carbon
             CFRunLoopRef rl,
             CFRunLoopSourceRef source,
             CFStringRef mode);
+
+        [DllImport(appServices, EntryPoint = "CFRunLoopRemoveSource")]
+        internal static extern void RunLoopRemoveSource(
+            CFRunLoopRef rl,
+            CFRunLoopSourceRef source,
+            CFStringRef mode);
     }
 }