From ad084e2604f2f0d64513131dd5eb8bb5434206bc Mon Sep 17 00:00:00 2001 From: Jamal Fanaian Date: Wed, 20 Feb 2013 16:56:11 -0500 Subject: [PATCH] Check if the deviceDesc is empty before parsing it. --- Source/OpenTK/Platform/Windows/WinRawMouse.cs | 35 ++++++++++--------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/Source/OpenTK/Platform/Windows/WinRawMouse.cs b/Source/OpenTK/Platform/Windows/WinRawMouse.cs index 38e8a3714..809887a2f 100644 --- a/Source/OpenTK/Platform/Windows/WinRawMouse.cs +++ b/Source/OpenTK/Platform/Windows/WinRawMouse.cs @@ -112,24 +112,27 @@ public void RefreshDevices() RegistryKey regkey = FindRegistryKey(name); string deviceDesc = (string)regkey.GetValue("DeviceDesc"); string deviceClass = (string)regkey.GetValue("Class"); - deviceDesc = deviceDesc.Substring(deviceDesc.LastIndexOf(';') + 1); - - if (!String.IsNullOrEmpty(deviceClass) && deviceClass.ToLower().Equals("mouse")) + if (!String.IsNullOrEmpty(deviceDesc)) { - if (!rawids.ContainsKey(new ContextHandle(dev.Device))) + deviceDesc = deviceDesc.Substring(deviceDesc.LastIndexOf(';') + 1); + + if (!String.IsNullOrEmpty(deviceClass) && deviceClass.ToLower().Equals("mouse")) { - // Register the device: - RawInputDeviceInfo info = new RawInputDeviceInfo(); - int devInfoSize = API.RawInputDeviceInfoSize; - Functions.GetRawInputDeviceInfo(dev.Device, RawInputDeviceInfoEnum.DEVICEINFO, - info, ref devInfoSize); - - RegisterRawDevice(Window, deviceDesc); - MouseState state = new MouseState(); - state.IsConnected = true; - mice.Add(state); - names.Add(deviceDesc); - rawids.Add(new ContextHandle(dev.Device), mice.Count - 1); + if (!rawids.ContainsKey(new ContextHandle(dev.Device))) + { + // Register the device: + RawInputDeviceInfo info = new RawInputDeviceInfo(); + int devInfoSize = API.RawInputDeviceInfoSize; + Functions.GetRawInputDeviceInfo(dev.Device, RawInputDeviceInfoEnum.DEVICEINFO, + info, ref devInfoSize); + + RegisterRawDevice(Window, deviceDesc); + MouseState state = new MouseState(); + state.IsConnected = true; + mice.Add(state); + names.Add(deviceDesc); + rawids.Add(new ContextHandle(dev.Device), mice.Count - 1); + } } } }