[Mac] Retain CFRunLoop while it is in use

This commit is contained in:
thefiddler 2014-07-22 16:20:46 +02:00
parent 42e4e0b27e
commit 7956126c8d

View file

@ -94,7 +94,7 @@ namespace OpenTK.Platform.MacOS
readonly Dictionary<int, IntPtr> JoystickIndexToDevice =
new Dictionary<int, IntPtr>();
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
{