Fixed double SDL_EVENT_GAMEPAD_ADDED for controllers with automatic gamepad mappings

This commit is contained in:
Sam Lantinga
2025-07-24 10:34:44 -07:00
parent 3fdd15adaa
commit 6babade758
2 changed files with 6 additions and 2 deletions

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;
} }

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);
} }
} }