all repos — mgba @ 062ba0767c25aaf647f3caf967f86bb860037066

mGBA Game Boy Advance Emulator

SDL: Fix handling of invalid gamepads (fixes #1239)
Vicki Pfau vi@endrift.com
Sun, 09 Dec 2018 18:33:52 -0800
commit

062ba0767c25aaf647f3caf967f86bb860037066

parent

759a1d27491332da7a051859e783abb33c492544

2 files changed, 32 insertions(+), 12 deletions(-)

jump to
M CHANGESCHANGES

@@ -142,6 +142,7 @@ - GBA Savedata: Fix EEPROM writing codepath when savetype is not EEPROM

- Core: Reroot timing list when (de)scheduling - GB Video: Changing LYC while LCDC off doesn't affect STAT (fixes mgba.io/i/1224) - GBA I/O: SOUNDCNT_HI is readable when sound is off + - SDL: Fix handling of invalid gamepads (fixes mgba.io/i/1239) Misc: - mGUI: Add SGB border configuration option - mGUI: Add support for different settings types
M src/platform/sdl/sdl-events.csrc/platform/sdl/sdl-events.c

@@ -64,8 +64,12 @@ // Some OSes don't do hotplug detection

if (!SDL_JoystickListSize(&context->joysticks)) { int i; for (i = 0; i < nJoysticks; ++i) { + SDL_Joystick* sdlJoystick = SDL_JoystickOpen(i); + if (!sdlJoystick) { + continue; + } struct SDL_JoystickCombo* joystick = SDL_JoystickListAppend(&context->joysticks); - joystick->joystick = SDL_JoystickOpen(i); + joystick->joystick = sdlJoystick; joystick->index = SDL_JoystickListSize(&context->joysticks) - 1; #if SDL_VERSION_ATLEAST(2, 0, 0) joystick->id = SDL_JoystickInstanceID(joystick->joystick);

@@ -203,6 +207,9 @@ joystickName = SDL_JoystickName(SDL_JoystickListGetPointer(&events->joysticks, i)->joystick);

#else joystickName = SDL_JoystickName(SDL_JoystickIndex(SDL_JoystickListGetPointer(&events->joysticks, i)->joystick)); #endif + if (!joystickName) { + continue; + } if (events->preferredJoysticks[player->playerId] && strcmp(events->preferredJoysticks[player->playerId], joystickName) == 0) { index = i; break;

@@ -253,6 +260,9 @@ const char* name = SDL_JoystickName(context->joystick->joystick);

#else const char* name = SDL_JoystickName(SDL_JoystickIndex(context->joystick->joystick)); #endif + if (!name) { + return; + } mInputProfileLoad(context->bindings, SDL_BINDING_BUTTON, config, name); const char* value;

@@ -304,6 +314,9 @@ const char* name = SDL_JoystickName(context->joystick->joystick);

#else const char* name = SDL_JoystickName(SDL_JoystickIndex(context->joystick->joystick)); #endif + if (!name) { + return; + } char value[16]; snprintf(value, sizeof(value), "%i", context->rotation.axisX); mInputSetCustomValue(config, "gba", SDL_BINDING_BUTTON, "tiltAxisX", value, name);

@@ -332,8 +345,12 @@ #if SDL_VERSION_ATLEAST(2, 0, 0)

SDL_Event event; while (SDL_PeepEvents(&event, 1, SDL_GETEVENT, SDL_JOYDEVICEADDED, SDL_JOYDEVICEREMOVED) > 0) { if (event.type == SDL_JOYDEVICEADDED) { + SDL_Joystick* sdlJoystick = SDL_JoystickOpen(event.jdevice.which); + if (!sdlJoystick) { + continue; + } struct SDL_JoystickCombo* joystick = SDL_JoystickListAppend(&events->joysticks); - joystick->joystick = SDL_JoystickOpen(event.jdevice.which); + joystick->joystick = sdlJoystick; joystick->id = SDL_JoystickInstanceID(joystick->joystick); joystick->index = SDL_JoystickListSize(&events->joysticks) - 1; #if SDL_VERSION_ATLEAST(2, 0, 0)

@@ -347,16 +364,18 @@ #else

joystickName = SDL_JoystickName(SDL_JoystickIndex(joystick->joystick)); #endif size_t i; - for (i = 0; (int) i < events->playersAttached; ++i) { - if (events->players[i]->joystick) { - continue; - } - if (events->preferredJoysticks[i] && strcmp(events->preferredJoysticks[i], joystickName) == 0) { - events->players[i]->joystick = joystick; - if (config) { - mInputProfileLoad(events->players[i]->bindings, SDL_BINDING_BUTTON, config, joystickName); + if (joystickName) { + for (i = 0; (int) i < events->playersAttached; ++i) { + if (events->players[i]->joystick) { + continue; + } + if (events->preferredJoysticks[i] && strcmp(events->preferredJoysticks[i], joystickName) == 0) { + events->players[i]->joystick = joystick; + if (config) { + mInputProfileLoad(events->players[i]->bindings, SDL_BINDING_BUTTON, config, joystickName); + } + return; } - return; } } for (i = 0; (int) i < events->playersAttached; ++i) {

@@ -364,7 +383,7 @@ if (events->players[i]->joystick) {

continue; } events->players[i]->joystick = joystick; - if (config) { + if (config && joystickName) { mInputProfileLoad(events->players[i]->bindings, SDL_BINDING_BUTTON, config, joystickName); } break;