From ddd070579a49445f3abcefdd210091e526615276 Mon Sep 17 00:00:00 2001
From: "Stefanos A." <stapostol@gmail.com>
Date: Mon, 30 Sep 2013 18:27:13 +0200
Subject: [PATCH] Workaround for NRE on WinRawMouse driver

On some systems, the Windows Raw Input driver fails to find the name of
a mouse device, causing a NRE. Since the name is not vital information,
a dummy name is generated as a workaround.
---
 Source/OpenTK/Platform/Windows/WinRawMouse.cs | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/Source/OpenTK/Platform/Windows/WinRawMouse.cs b/Source/OpenTK/Platform/Windows/WinRawMouse.cs
index 82ad21a9..727d3b6a 100644
--- a/Source/OpenTK/Platform/Windows/WinRawMouse.cs
+++ b/Source/OpenTK/Platform/Windows/WinRawMouse.cs
@@ -120,7 +120,14 @@ namespace OpenTK.Platform.Windows
                             RegistryKey classGUIDKey = Registry.LocalMachine.OpenSubKey(@"SYSTEM\CurrentControlSet\Control\Class\" + deviceClassGUID);
                             deviceClass = classGUIDKey != null ? (string) classGUIDKey.GetValue("Class") : string.Empty;
                         }
-                        deviceDesc = deviceDesc.Substring(deviceDesc.LastIndexOf(';') + 1);
+
+                        // deviceDesc remained null on a new Win7 system - not sure why.
+                        // Since the description is not vital information, use a dummy description
+                        // when that happens.
+                        if (String.IsNullOrEmpty(deviceDesc))
+                            deviceDesc = "Windows Mouse " + mice.Count;
+                        else
+                            deviceDesc = deviceDesc.Substring(deviceDesc.LastIndexOf(';') + 1);
 
                         if (!String.IsNullOrEmpty(deviceClass) && deviceClass.ToLower().Equals("mouse"))
                         {