From 7956126c8d20cb5ae937867ecde5bb8468048231 Mon Sep 17 00:00:00 2001 From: thefiddler Date: Tue, 22 Jul 2014 16:20:46 +0200 Subject: [PATCH] [Mac] Retain CFRunLoop while it is in use --- Source/OpenTK/Platform/MacOS/HIDInput.cs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/Source/OpenTK/Platform/MacOS/HIDInput.cs b/Source/OpenTK/Platform/MacOS/HIDInput.cs index 19c9d80..375e772 100755 --- a/Source/OpenTK/Platform/MacOS/HIDInput.cs +++ b/Source/OpenTK/Platform/MacOS/HIDInput.cs @@ -94,7 +94,7 @@ namespace OpenTK.Platform.MacOS readonly Dictionary JoystickIndexToDevice = new Dictionary(); - readonly CFRunLoop RunLoop = CF.CFRunLoopGetMain(); + readonly CFRunLoop RunLoop; readonly CFString InputLoopMode = CF.RunLoopModeDefault; readonly CFDictionary DeviceTypes = new CFDictionary(); @@ -118,6 +118,16 @@ namespace OpenTK.Platform.MacOS { Debug.Print("Using HIDInput."); + RunLoop = CF.CFRunLoopGetMain(); + if (RunLoop == IntPtr.Zero) + RunLoop = CF.CFRunLoopGetCurrent(); + if (RunLoop == IntPtr.Zero) + { + Debug.Print("[Error] No CFRunLoop found for {0}", GetType().FullName); + throw new InvalidOperationException(); + } + CF.CFRetain(RunLoop); + HandleDeviceAdded = DeviceAdded; HandleDeviceRemoved = DeviceRemoved; HandleDeviceValueReceived = DeviceValueReceived; @@ -1776,6 +1786,11 @@ namespace OpenTK.Platform.MacOS NativeMethods.IOHIDManagerClose(hidmanager, IOOptionBits.Zero); hidmanager = IntPtr.Zero; } + + if (RunLoop != IntPtr.Zero) + { + CF.CFRelease(RunLoop); + } } else { -- 2.7.4