mirror of https://github.com/mgba-emu/mgba.git
SDL: Refresh stale pointers after adding a joystick (fixes #1622)
This commit is contained in:
parent
24a90e317f
commit
d292b6190c
1
CHANGES
1
CHANGES
|
@ -28,6 +28,7 @@ Other fixes:
|
||||||
- Qt: Fix non-GB build (fixes mgba.io/i/1664)
|
- Qt: Fix non-GB build (fixes mgba.io/i/1664)
|
||||||
- Qt: Fix pausing Qt Multimedia audio (fixes mgba.io/i/1643)
|
- Qt: Fix pausing Qt Multimedia audio (fixes mgba.io/i/1643)
|
||||||
- Qt: Fix invalid names for modifier keys (fixes mgba.io/i/525)
|
- Qt: Fix invalid names for modifier keys (fixes mgba.io/i/525)
|
||||||
|
- SDL: Refresh stale pointers after adding a joystick (fixes mgba.io/i/1622)
|
||||||
- Util: Fix crash reading invalid ELFs
|
- Util: Fix crash reading invalid ELFs
|
||||||
- VFS: Fix handle leak when double-mapping (fixes mgba.io/i/1659)
|
- VFS: Fix handle leak when double-mapping (fixes mgba.io/i/1659)
|
||||||
Misc:
|
Misc:
|
||||||
|
|
|
@ -351,6 +351,13 @@ void mSDLUpdateJoysticks(struct mSDLEvents* events, const struct Configuration*
|
||||||
if (!sdlJoystick) {
|
if (!sdlJoystick) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
ssize_t joysticks[MAX_PLAYERS];
|
||||||
|
size_t i;
|
||||||
|
// Pointers can get invalidated, so we'll need to refresh them
|
||||||
|
for (i = 0; i < events->playersAttached && i < MAX_PLAYERS; ++i) {
|
||||||
|
joysticks[i] = events->players[i]->joystick ? SDL_JoystickListIndex(&events->joysticks, events->players[i]->joystick) : SIZE_MAX;
|
||||||
|
events->players[i]->joystick = NULL;
|
||||||
|
}
|
||||||
struct SDL_JoystickCombo* joystick = SDL_JoystickListAppend(&events->joysticks);
|
struct SDL_JoystickCombo* joystick = SDL_JoystickListAppend(&events->joysticks);
|
||||||
joystick->joystick = sdlJoystick;
|
joystick->joystick = sdlJoystick;
|
||||||
joystick->id = SDL_JoystickInstanceID(joystick->joystick);
|
joystick->id = SDL_JoystickInstanceID(joystick->joystick);
|
||||||
|
@ -358,8 +365,12 @@ void mSDLUpdateJoysticks(struct mSDLEvents* events, const struct Configuration*
|
||||||
#if SDL_VERSION_ATLEAST(2, 0, 0)
|
#if SDL_VERSION_ATLEAST(2, 0, 0)
|
||||||
joystick->haptic = SDL_HapticOpenFromJoystick(joystick->joystick);
|
joystick->haptic = SDL_HapticOpenFromJoystick(joystick->joystick);
|
||||||
#endif
|
#endif
|
||||||
|
for (i = 0; i < events->playersAttached && i < MAX_PLAYERS; ++i) {
|
||||||
|
if (joysticks[i] != SIZE_MAX) {
|
||||||
|
events->players[i]->joystick = SDL_JoystickListGetPointer(&events->joysticks, joysticks[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
size_t i;
|
|
||||||
#if SDL_VERSION_ATLEAST(2, 0, 0)
|
#if SDL_VERSION_ATLEAST(2, 0, 0)
|
||||||
char joystickName[34] = {0};
|
char joystickName[34] = {0};
|
||||||
SDL_JoystickGetGUIDString(SDL_JoystickGetGUID(joystick->joystick), joystickName, sizeof(joystickName));
|
SDL_JoystickGetGUIDString(SDL_JoystickGetGUID(joystick->joystick), joystickName, sizeof(joystickName));
|
||||||
|
|
Loading…
Reference in New Issue