Fix crash from disconnecting controllers with XInput (squashed PR #2783)

This commit is contained in:
Alan Unger 2021-06-08 12:35:35 -04:00 committed by GitHub
parent eaff9274cb
commit 2549c3fa04
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 2 deletions

View File

@ -48,6 +48,8 @@ namespace BizHawk.Bizware.DirectX
{
foreach (var pad in GamePad360.EnumerateDevices())
{
if (!pad.IsConnected)
continue;
for (int b = 0, n = pad.NumButtons; b < n; b++) handleButton(pad.InputNamePrefix + pad.ButtonName(b), pad.Pressed(b), ClientInputFocus.Pad);
foreach (var (axisName, f) in pad.GetAxes()) handleAxis(pad.InputNamePrefix + axisName, (int) f);
_lastHapticsSnapshot.TryGetValue(pad.InputNamePrefix + "Left", out var leftStrength);

View File

@ -121,7 +121,7 @@ namespace BizHawk.Bizware.DirectX
private XINPUT_STATE _state;
public int PlayerNumber => (int)_index0 + 1;
public bool IsConnected => _controller.IsConnected;
public readonly string InputNamePrefix;
private GamePad360(uint index0, Controller c)
@ -236,7 +236,15 @@ namespace BizHawk.Bizware.DirectX
public void SetVibration(int left, int right)
{
static ushort Conv(int i) => unchecked((ushort) ((i >> 15) & 0xFFFF));
_controller.SetVibration(new() { LeftMotorSpeed = Conv(left), RightMotorSpeed = Conv(right) });
try
{
_controller.SetVibration(new() { LeftMotorSpeed = Conv(left), RightMotorSpeed = Conv(right) });
}
catch (XInputException)
{
// Ignored, most likely the controller disconnected
}
}
}
}