Skip to content

Commit

Permalink
[Win] Check registry keys before accessing
Browse files Browse the repository at this point in the history
Fixes crashes when using OpenTK over the Remote Desktop Client for Mac
(version 2010).
  • Loading branch information
thefiddler committed Jan 8, 2014
1 parent 811126c commit 1b3b510
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
10 changes: 8 additions & 2 deletions Source/OpenTK/Platform/Windows/WinRawKeyboard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,11 @@ public void RefreshDevices()
// This is a keyboard or USB keyboard device. In the latter case, discover if it really is a
// keyboard device by qeurying the registry.
RegistryKey regkey = GetRegistryKey(name);
string deviceDesc = (string)regkey.GetValue("DeviceDesc");
if (regkey == null)
continue;

string deviceDesc = (string)regkey.GetValue("DeviceDesc");
string deviceClass = (string)regkey.GetValue("Class");

string deviceClassGUID = (string)regkey.GetValue("ClassGUID"); // for windows 8 support via OpenTK issue 3198

// making a guess at backwards compatability. Not sure what older windows returns in these cases...
Expand Down Expand Up @@ -205,10 +206,15 @@ public bool ProcessKeyboardEvent(RawInput rin)

static RegistryKey GetRegistryKey(string name)
{
if (name.Length < 4)
return null;

// remove the \??\
name = name.Substring(4);

string[] split = name.Split('#');
if (split.Length < 3)
return null;

string id_01 = split[0]; // ACPI (Class code)
string id_02 = split[1]; // PNP0303 (SubClass code)
Expand Down
13 changes: 10 additions & 3 deletions Source/OpenTK/Platform/Windows/WinRawMouse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,13 @@ public void RefreshDevices()
// This is a mouse or a USB mouse device. In the latter case, discover if it really is a
// mouse device by qeurying the registry.
RegistryKey regkey = FindRegistryKey(name);
string deviceDesc = (string)regkey.GetValue("DeviceDesc");
if (regkey == null)
continue;


string deviceDesc = (string)regkey.GetValue("DeviceDesc");
string deviceClass = (string)regkey.GetValue("Class") as string;
if(deviceClass == null){
if(deviceClass == null)
{
// Added to address OpenTK issue 3198 with mouse on Windows 8
string deviceClassGUID = (string)regkey.GetValue("ClassGUID");
RegistryKey classGUIDKey = Registry.LocalMachine.OpenSubKey(@"SYSTEM\CurrentControlSet\Control\Class\" + deviceClassGUID);
Expand Down Expand Up @@ -266,10 +268,15 @@ static string GetDeviceName(RawInputDeviceList dev)

static RegistryKey FindRegistryKey(string name)
{
if (name.Length < 4)
return null;

// remove the \??\
name = name.Substring(4);

string[] split = name.Split('#');
if (split.Length < 3)
return null;

string id_01 = split[0]; // ACPI (Class code)
string id_02 = split[1]; // PNP0303 (SubClass code)
Expand Down

0 comments on commit 1b3b510

Please sign in to comment.