Commit b7b8ef59a33d3ed00f4303c1afa740a353a30419

Sylvain Becker 2020-10-07T17:32:07

Fixed bug 5307 - Crash when joysticks hats number is odd (Thanks Sockmonsters!)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
diff --git a/android-project/app/src/main/java/org/libsdl/app/SDLControllerManager.java b/android-project/app/src/main/java/org/libsdl/app/SDLControllerManager.java
index 05674d1..d21788b 100644
--- a/android-project/app/src/main/java/org/libsdl/app/SDLControllerManager.java
+++ b/android-project/app/src/main/java/org/libsdl/app/SDLControllerManager.java
@@ -263,10 +263,10 @@ class SDLJoystickHandler_API16 extends SDLJoystickHandler {
                             float value = ( event.getAxisValue( range.getAxis(), actionPointerIndex) - range.getMin() ) / range.getRange() * 2.0f - 1.0f;
                             SDLControllerManager.onNativeJoy(joystick.device_id, i, value );
                         }
-                        for (int i = 0; i < joystick.hats.size(); i+=2) {
-                            int hatX = Math.round(event.getAxisValue( joystick.hats.get(i).getAxis(), actionPointerIndex ) );
-                            int hatY = Math.round(event.getAxisValue( joystick.hats.get(i+1).getAxis(), actionPointerIndex ) );
-                            SDLControllerManager.onNativeHat(joystick.device_id, i/2, hatX, hatY );
+                        for (int i = 0; i < joystick.hats.size()/2; i++) {
+                            int hatX = Math.round(event.getAxisValue( joystick.hats.get(2 * i).getAxis(), actionPointerIndex ));
+                            int hatY = Math.round(event.getAxisValue( joystick.hats.get(2 * i + 1).getAxis(), actionPointerIndex ));
+                            SDLControllerManager.onNativeHat(joystick.device_id, i, hatX, hatY);
                         }
                     }
                     break;