Commit a70bb58d4b97309a321a088f6540ebc6ccc278d0

Sylvain Becker 2020-10-05T14:09:31

Android: fix joystick allocation that can be never used

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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 a81e97b..d6db065 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
@@ -180,9 +180,9 @@ class SDLJoystickHandler_API16 extends SDLJoystickHandler {
         for(int i=0; i < deviceIds.length; ++i) {
             SDLJoystick joystick = getJoystick(deviceIds[i]);
             if (joystick == null) {
-                joystick = new SDLJoystick();
                 InputDevice joystickDevice = InputDevice.getDevice(deviceIds[i]);
                 if (SDLControllerManager.isDeviceSDLJoystick(deviceIds[i])) {
+                    joystick = new SDLJoystick();
                     joystick.device_id = deviceIds[i];
                     joystick.name = joystickDevice.getName();
                     joystick.desc = getJoystickDescriptor(joystickDevice);