From 49e9134774de9b4c82b09637c08a7845caa33cc4 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.
(cherry picked from commit afd1e5102321cfa3c8e0798bbee159452f51ef4d)
---
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 6293519ca61fc..4f45b4cd6e7e2 100644
--- a/src/joystick/hidapi/SDL_hidapijoystick.c
+++ b/src/joystick/hidapi/SDL_hidapijoystick.c
@@ -751,11 +751,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;
}