From afd1e5102321cfa3c8e0798bbee159452f51ef4d Mon Sep 17 00:00:00 2001
From: "Joe [ReRezd]" <[EMAIL REDACTED]>
Date: Mon, 19 May 2025 00:36:55 -0400
Subject: [PATCH] Fix: GameCube controller adapter hotplug not working
SDL_PrivateJoystickAdded was called before setting the InstanceId in the adapters ctx->joysticks array. This would eventually broadcast the SDL_EVENT_JOYSTICK_ADDED event with the new InstanceId, if your program listens for the added events and opens joysticks at that point it would always fail because there would be no matching InstanceId in the ctx->joysticks array.
---
src/joystick/hidapi/SDL_hidapijoystick.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/src/joystick/hidapi/SDL_hidapijoystick.c b/src/joystick/hidapi/SDL_hidapijoystick.c
index 119177bbcdf1f..a616db3b9a8b4 100644
--- a/src/joystick/hidapi/SDL_hidapijoystick.c
+++ b/src/joystick/hidapi/SDL_hidapijoystick.c
@@ -764,11 +764,12 @@ bool HIDAPI_JoystickConnected(SDL_HIDAPI_Device *device, SDL_JoystickID *pJoysti
++SDL_HIDAPI_numjoysticks;
- SDL_PrivateJoystickAdded(joystickID);
-
if (pJoystickID) {
*pJoystickID = joystickID;
}
+
+ SDL_PrivateJoystickAdded(joystickID);
+
return true;
}