Fix crash due to crash when a controller isn't recognized

This commit is contained in:
SerpentSpirale authored and SerpentSpirale committed 2021-07-22 21:56:35 +02:00
1 parent 7835a76a95
commit 2fa4a2756e
1 file changed
+3 -2
@@ -27,8 +27,9 @@ public class GamepadJoystick {
this.verticalAxis = verticalAxis;
this.horizontalAxis = horizontalAxis;
deadzone = Math.max(device.getMotionRange(verticalAxis).getFlat(),
device.getMotionRange(horizontalAxis).getFlat()) * 2f;
//Some controllers aren't recognized as such by android, so we fallback to a default value of 0.2
deadzone = device != null ? Math.max(device.getMotionRange(verticalAxis).getFlat(),
device.getMotionRange(horizontalAxis).getFlat()) * 2f : 0.2f;
if(deadzone < 0.15) deadzone = 0.15f;
}