Fixed double SDL_EVENT_GAMEPAD_ADDED for controllers with automatic gamepad mappings

This commit is contained in:
Sam Lantinga committed 2025-07-24 10:36:09 -07:00
1 parent 3fdd15adaa
commit 6babade758
2 files changed
+6 -2

No files matched your search

+1 -1
View File
@@ -312,7 +312,7 @@ void SDL_PrivateGamepadAdded(SDL_JoystickID instance_id)
{ {
SDL_Event event; SDL_Event event;
if (!SDL_gamepads_initialized) { if (!SDL_gamepads_initialized || SDL_IsJoystickBeingAdded()) {
return; return;
} }
+5 -1
View File
@@ -2316,6 +2316,7 @@ void SDL_PrivateJoystickAdded(SDL_JoystickID instance_id)
SDL_JoystickDriver *driver; SDL_JoystickDriver *driver;
int device_index; int device_index;
int player_index = -1; int player_index = -1;
bool is_gamepad;
SDL_AssertJoysticksLocked(); SDL_AssertJoysticksLocked();
@@ -2350,9 +2351,12 @@ void SDL_PrivateJoystickAdded(SDL_JoystickID instance_id)
} }
} }
// This might create an automatic gamepad mapping, so wait to send the event
is_gamepad = SDL_IsGamepad(instance_id);
SDL_joystick_being_added = false; SDL_joystick_being_added = false;
if (SDL_IsGamepad(instance_id)) { if (is_gamepad) {
SDL_PrivateGamepadAdded(instance_id); SDL_PrivateGamepadAdded(instance_id);
} }
} }