From bb882fe700873fe30544e2b920ccbcb2a676b3ed Mon Sep 17 00:00:00 2001 From: thefiddler Date: Wed, 23 Jul 2014 23:21:04 +0200 Subject: [PATCH] [Mac] Correctly release mach port The event tap is released automatically along with the mach port. Fixes crash on shutdown. --- Source/OpenTK/Platform/MacOS/HIDInput.cs | 8 +++----- Source/OpenTK/Platform/MacOS/Quartz/CoreFoundation.cs | 6 ++++++ 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/Source/OpenTK/Platform/MacOS/HIDInput.cs b/Source/OpenTK/Platform/MacOS/HIDInput.cs index e2014c4..4c3e454 100755 --- a/Source/OpenTK/Platform/MacOS/HIDInput.cs +++ b/Source/OpenTK/Platform/MacOS/HIDInput.cs @@ -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; } diff --git a/Source/OpenTK/Platform/MacOS/Quartz/CoreFoundation.cs b/Source/OpenTK/Platform/MacOS/Quartz/CoreFoundation.cs index 262fd7f..a11b9b9 100644 --- a/Source/OpenTK/Platform/MacOS/Quartz/CoreFoundation.cs +++ b/Source/OpenTK/Platform/MacOS/Quartz/CoreFoundation.cs @@ -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); } } -- 2.7.4