From 383cea7e82f3a8eb9669d8ea5cb4937cc000dfba Mon Sep 17 00:00:00 2001 From: thefiddler Date: Sat, 20 Sep 2014 17:11:18 +0200 Subject: [PATCH] [Mac] Fixed exception in HIDInput.Dispose() HIDInput.Dispose() would remove elements from a DeviceCollection during iteration. This results in an exception. We are now using a plain for-loop instead. --- Source/OpenTK/Platform/MacOS/HIDInput.cs | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/Source/OpenTK/Platform/MacOS/HIDInput.cs b/Source/OpenTK/Platform/MacOS/HIDInput.cs index a743954d..88c3b8f4 100755 --- a/Source/OpenTK/Platform/MacOS/HIDInput.cs +++ b/Source/OpenTK/Platform/MacOS/HIDInput.cs @@ -1704,19 +1704,28 @@ namespace OpenTK.Platform.MacOS NativeMethods.IOHIDManagerUnscheduleFromRunLoop( hidmanager, RunLoop, InputLoopMode); - foreach (var device in MouseDevices) + for (int i = 0; i < Math.Max(MouseDevices.Count, 4); i++) { - DeviceRemoved(IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, device.Id); + if (MouseDevices[i] != null) + { + DeviceRemoved(IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, MouseDevices[i].Id); + } } - foreach (var device in KeyboardDevices) + for (int i = 0; i < Math.Max(KeyboardDevices.Count, 4); i++) { - DeviceRemoved(IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, device.Id); + if (KeyboardDevices[i] != null) + { + DeviceRemoved(IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, KeyboardDevices[i].Id); + } } - foreach (var device in JoystickDevices) + for (int i = 0; i < Math.Max(JoystickDevices.Count, 4); i++) { - DeviceRemoved(IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, device.Id); + if (JoystickDevices[i] != null) + { + DeviceRemoved(IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, JoystickDevices[i].Id); + } } if (hidmanager != IntPtr.Zero)