[Mac] Explicitly close removed devices

Devices are now explicitly closed when they a DeviceRemoved event is
received. Additionally, exceptions are no longer allowed to escape into
unmanaged code, where they might crash the runtime.
This commit is contained in:
thefiddler 2014-07-23 21:19:46 +02:00
parent d12643cf44
commit 57c2f89038

View file

@ -179,6 +179,8 @@ namespace OpenTK.Platform.MacOS
CGEventType type, CGEventType type,
IntPtr @event, IntPtr @event,
IntPtr refcon) IntPtr refcon)
{
try
{ {
CursorState.SetIsConnected(true); CursorState.SetIsConnected(true);
@ -228,6 +230,12 @@ namespace OpenTK.Platform.MacOS
} }
break; break;
} }
}
catch (Exception e)
{
// Do not let any exceptions escape into unmanaged code!
Debug.Print(e.ToString());
}
return @event; return @event;
} }
@ -336,6 +344,7 @@ namespace OpenTK.Platform.MacOS
{ {
NativeMethods.IOHIDDeviceRegisterInputValueCallback(device, IntPtr.Zero, IntPtr.Zero); NativeMethods.IOHIDDeviceRegisterInputValueCallback(device, IntPtr.Zero, IntPtr.Zero);
NativeMethods.IOHIDDeviceUnscheduleFromRunLoop(device, RunLoop, InputLoopMode); NativeMethods.IOHIDDeviceUnscheduleFromRunLoop(device, RunLoop, InputLoopMode);
NativeMethods.IOHIDDeviceClose(device, IOOptionBits.Zero);
} }
} }
catch (Exception e) catch (Exception e)
@ -1093,7 +1102,7 @@ namespace OpenTK.Platform.MacOS
[DllImport(hid)] [DllImport(hid)]
public static extern void IOHIDManagerSetDeviceMatching( public static extern void IOHIDManagerSetDeviceMatching(
IOHIDManagerRef manager, IOHIDManagerRef manager,
CFDictionaryRef matching) ; CFDictionaryRef matching);
[DllImport(hid)] [DllImport(hid)]
public static extern IOReturn IOHIDManagerOpen( public static extern IOReturn IOHIDManagerOpen(
@ -1105,6 +1114,11 @@ namespace OpenTK.Platform.MacOS
IOHIDDeviceRef manager, IOHIDDeviceRef manager,
IOOptionBits opts); IOOptionBits opts);
[DllImport(hid)]
public static extern IOReturn IOHIDDeviceClose(
IOHIDDeviceRef device,
IOOptionBits options);
[DllImport(hid)] [DllImport(hid)]
public static extern CFTypeRef IOHIDDeviceGetProperty( public static extern CFTypeRef IOHIDDeviceGetProperty(
IOHIDDeviceRef device, IOHIDDeviceRef device,