From 958d59bbb3d5d1b5eefc1391478faa13a5177975 Mon Sep 17 00:00:00 2001 From: Alexander Scheurer Date: Fri, 7 May 2021 22:47:50 +0200 Subject: [PATCH] Catch gamepad input exceptions --- src/Engine/Imp/Graphics/Desktop/InputImp.cs | 37 ++++++++++++++++----- 1 file changed, 28 insertions(+), 9 deletions(-) diff --git a/src/Engine/Imp/Graphics/Desktop/InputImp.cs b/src/Engine/Imp/Graphics/Desktop/InputImp.cs index 941340e050..6a6ac6fd0d 100644 --- a/src/Engine/Imp/Graphics/Desktop/InputImp.cs +++ b/src/Engine/Imp/Graphics/Desktop/InputImp.cs @@ -300,7 +300,14 @@ public string Id get { - return GLFW.GetGamepadName(DeviceID); + try + { + return GLFW.GetGamepadName(DeviceID); + } + catch + { + return "No gamepad connected"; + } } } /// @@ -479,11 +486,17 @@ public float GetAxis(int iAxisId) { JoystickState state = _gameWindow.JoystickStates[DeviceID]; if (state != null) - return state.GetAxis(iAxisId); - + { + try + { + return state.GetAxis(iAxisId); + } + catch + { + return 0; + } + } return 0; - - //throw new InvalidOperationException($"Unknown axis {iAxisId}. Cannot get value for unknown axis."); } /// @@ -493,11 +506,17 @@ public bool GetButton(int iButtonId) { JoystickState state = _gameWindow.JoystickStates[DeviceID]; if (state != null) - return state.IsButtonDown(iButtonId); - + { + try + { + return state.IsButtonDown(iButtonId); + } + catch + { + return false; + } + } return false; - - //throw new InvalidOperationException($"Unknown button {iButtonId}. Cannot get value for unknown button."); } }