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();
{
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;
NativeMethods.IOHIDManagerClose(hidmanager, IOOptionBits.Zero);
hidmanager = IntPtr.Zero;
}
+
+ if (RunLoop != IntPtr.Zero)
+ {
+ CF.CFRelease(RunLoop);
+ }
}
else
{