Fix crash on controllers with RX and RY but no Z and RZ axes

This commit is contained in:
Cameron Gutman
2019-10-16 19:02:51 -07:00
parent d46053f8d6
commit 3bcc1c84bb

View File

@@ -502,8 +502,14 @@ public class ControllerHandler implements InputManager.InputDeviceListener, UsbD
// other sane controller that uses RX and RY for right stick and Z and RZ for triggers.
context.rightStickXAxis = MotionEvent.AXIS_RX;
context.rightStickYAxis = MotionEvent.AXIS_RY;
context.leftTriggerAxis = MotionEvent.AXIS_Z;
context.rightTriggerAxis = MotionEvent.AXIS_RZ;
// While it's likely that Z and RZ are triggers, we may have digital trigger buttons
// instead. We must check that we actually have Z and RZ axes before assigning them.
if (getMotionRangeForJoystickAxis(dev, MotionEvent.AXIS_Z) != null &&
getMotionRangeForJoystickAxis(dev, MotionEvent.AXIS_RZ) != null) {
context.leftTriggerAxis = MotionEvent.AXIS_Z;
context.rightTriggerAxis = MotionEvent.AXIS_RZ;
}
}
// Triggers always idle negative on axes that are centered at zero