From de13c62968f74456f128a64b9b5d0610b206b4d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Mizera?= Date: Sun, 17 Jan 2016 14:27:12 +0100 Subject: [PATCH] Fixed crash when no gamepad is connected --- MFIGamepadFeeder/Gamepads/GamepadManager.cs | 27 +++++++++++++++------ MFIGamepadFeeder/Properties/AssemblyInfo.cs | 4 +-- 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/MFIGamepadFeeder/Gamepads/GamepadManager.cs b/MFIGamepadFeeder/Gamepads/GamepadManager.cs index d1fb7c2..fc55fd9 100644 --- a/MFIGamepadFeeder/Gamepads/GamepadManager.cs +++ b/MFIGamepadFeeder/Gamepads/GamepadManager.cs @@ -99,13 +99,16 @@ public void Refresh() public void SetupGamepad(HidDeviceRepresentation hidDeviceRepresentation, uint gamePadId, GamepadConfiguration config) { - var device = - _hidDeviceLoader.GetDevices( - hidDeviceRepresentation.VendorId, - hidDeviceRepresentation.ProductId, - hidDeviceRepresentation.ProductVersion, - hidDeviceRepresentation.SerialNumber - ).First(); + try + { + var device = + _hidDeviceLoader.GetDevices( + hidDeviceRepresentation.VendorId, + hidDeviceRepresentation.ProductId, + hidDeviceRepresentation.ProductVersion, + hidDeviceRepresentation.SerialNumber + ).First(); + if (device == null) { @@ -139,6 +142,11 @@ public void SetupGamepad(HidDeviceRepresentation hidDeviceRepresentation, uint g { continue; } + catch (Exception ex) + { + Log(ex.Message); + break; + } if (count > 0) { @@ -146,6 +154,11 @@ public void SetupGamepad(HidDeviceRepresentation hidDeviceRepresentation, uint g } } } + } + catch (Exception ex) + { + Log(ex.Message); + } } private async Task GetConfigFromFilePath(string filePath) diff --git a/MFIGamepadFeeder/Properties/AssemblyInfo.cs b/MFIGamepadFeeder/Properties/AssemblyInfo.cs index 843a28b..4d86bb7 100644 --- a/MFIGamepadFeeder/Properties/AssemblyInfo.cs +++ b/MFIGamepadFeeder/Properties/AssemblyInfo.cs @@ -51,5 +51,5 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] +[assembly: AssemblyVersion("1.0.1.0")] +[assembly: AssemblyFileVersion("1.0.1.0")]