diff --git a/Source/OpenTK/Platform/MacOS/HIDInput.cs b/Source/OpenTK/Platform/MacOS/HIDInput.cs index 19c9d806..375e7723 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 {