Skip to content

Commit 6babade

Browse files
committed
Fixed double SDL_EVENT_GAMEPAD_ADDED for controllers with automatic gamepad mappings
1 parent 3fdd15a commit 6babade

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

src/joystick/SDL_gamepad.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ void SDL_PrivateGamepadAdded(SDL_JoystickID instance_id)
312312
{
313313
SDL_Event event;
314314

315-
if (!SDL_gamepads_initialized) {
315+
if (!SDL_gamepads_initialized || SDL_IsJoystickBeingAdded()) {
316316
return;
317317
}
318318

src/joystick/SDL_joystick.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2316,6 +2316,7 @@ void SDL_PrivateJoystickAdded(SDL_JoystickID instance_id)
23162316
SDL_JoystickDriver *driver;
23172317
int device_index;
23182318
int player_index = -1;
2319+
bool is_gamepad;
23192320

23202321
SDL_AssertJoysticksLocked();
23212322

@@ -2350,9 +2351,12 @@ void SDL_PrivateJoystickAdded(SDL_JoystickID instance_id)
23502351
}
23512352
}
23522353

2354+
// This might create an automatic gamepad mapping, so wait to send the event
2355+
is_gamepad = SDL_IsGamepad(instance_id);
2356+
23532357
SDL_joystick_being_added = false;
23542358

2355-
if (SDL_IsGamepad(instance_id)) {
2359+
if (is_gamepad) {
23562360
SDL_PrivateGamepadAdded(instance_id);
23572361
}
23582362
}

0 commit comments

Comments
 (0)