Skip to content

Commit

Permalink
Catch gamepad input exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
ASPePeX committed May 7, 2021
1 parent 8c3a93a commit 958d59b
Showing 1 changed file with 28 additions and 9 deletions.
37 changes: 28 additions & 9 deletions src/Engine/Imp/Graphics/Desktop/InputImp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,14 @@ public string Id

get
{
return GLFW.GetGamepadName(DeviceID);
try
{
return GLFW.GetGamepadName(DeviceID);
}
catch
{
return "No gamepad connected";
}
}
}
/// <summary>
Expand Down Expand Up @@ -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.");
}

/// <summary>
Expand All @@ -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.");
}
}

Expand Down

0 comments on commit 958d59b

Please sign in to comment.