Fix crash from disconnecting controllers with XInput (squashed PR #2783)
This commit is contained in:
parent
eaff9274cb
commit
2549c3fa04
|
@ -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);
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue