Commit 2cc70ca39e07f4e29effdf2389ede9f463543826

Sam Lantinga 2021-01-29T13:04:01

Fixed crash if the GameCube controller hasn't been opened yet

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
diff --git a/src/joystick/hidapi/SDL_hidapi_gamecube.c b/src/joystick/hidapi/SDL_hidapi_gamecube.c
index 83db51f..9d6ddd8 100644
--- a/src/joystick/hidapi/SDL_hidapi_gamecube.c
+++ b/src/joystick/hidapi/SDL_hidapi_gamecube.c
@@ -253,6 +253,10 @@ HIDAPI_DriverGameCube_HandleJoystickPacket(SDL_HIDAPI_Device *device, SDL_Driver
     }
 
     joystick = SDL_JoystickFromInstanceID(ctx->joysticks[i]);
+    if (!joystick) {
+        /* Hasn't been opened yet, skip */
+        return;
+    }
 
     #define READ_BUTTON(off, flag, button) \
         SDL_PrivateJoystickButton( \