mirror of https://github.com/mgba-emu/mgba.git
SDL: Fix potential race condition when pressing keys (fixes #872)
This commit is contained in:
parent
d582cf7d36
commit
8d1b41f695
1
CHANGES
1
CHANGES
|
@ -38,6 +38,7 @@ Bugfixes:
|
||||||
- GB Audio: Fix NRx2 writes while active (fixes mgba.io/i/866)
|
- GB Audio: Fix NRx2 writes while active (fixes mgba.io/i/866)
|
||||||
- GBA BIOS: Use core's VRAM variable instead of renderer's
|
- GBA BIOS: Use core's VRAM variable instead of renderer's
|
||||||
- GBA Savedata: Fix 512 byte EEPROM saving as 8kB (fixes mgba.io/i/877)
|
- GBA Savedata: Fix 512 byte EEPROM saving as 8kB (fixes mgba.io/i/877)
|
||||||
|
- SDL: Fix potential race condition when pressing keys (fixes mgba.io/i/872)
|
||||||
Misc:
|
Misc:
|
||||||
- GBA Timer: Use global cycles for timers
|
- GBA Timer: Use global cycles for timers
|
||||||
- GBA: Extend oddly-sized ROMs to full address space (fixes mgba.io/i/722)
|
- GBA: Extend oddly-sized ROMs to full address space (fixes mgba.io/i/722)
|
||||||
|
|
|
@ -411,11 +411,13 @@ static void _mSDLHandleKeypress(struct mCoreThread* context, struct mSDLPlayer*
|
||||||
key = mInputMapKey(sdlContext->bindings, SDL_BINDING_KEY, event->keysym.sym);
|
key = mInputMapKey(sdlContext->bindings, SDL_BINDING_KEY, event->keysym.sym);
|
||||||
}
|
}
|
||||||
if (key != -1) {
|
if (key != -1) {
|
||||||
|
mCoreThreadInterrupt(context);
|
||||||
if (event->type == SDL_KEYDOWN) {
|
if (event->type == SDL_KEYDOWN) {
|
||||||
context->core->addKeys(context->core, 1 << key);
|
context->core->addKeys(context->core, 1 << key);
|
||||||
} else {
|
} else {
|
||||||
context->core->clearKeys(context->core, 1 << key);
|
context->core->clearKeys(context->core, 1 << key);
|
||||||
}
|
}
|
||||||
|
mCoreThreadContinue(context);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (event->keysym.sym == SDLK_TAB) {
|
if (event->keysym.sym == SDLK_TAB) {
|
||||||
|
@ -516,21 +518,23 @@ static void _mSDLHandleKeypress(struct mCoreThread* context, struct mSDLPlayer*
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void _mSDLHandleJoyButton(struct mCore* core, struct mSDLPlayer* sdlContext, const struct SDL_JoyButtonEvent* event) {
|
static void _mSDLHandleJoyButton(struct mCoreThread* context, struct mSDLPlayer* sdlContext, const struct SDL_JoyButtonEvent* event) {
|
||||||
int key = 0;
|
int key = 0;
|
||||||
key = mInputMapKey(sdlContext->bindings, SDL_BINDING_BUTTON, event->button);
|
key = mInputMapKey(sdlContext->bindings, SDL_BINDING_BUTTON, event->button);
|
||||||
if (key == -1) {
|
if (key == -1) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mCoreThreadInterrupt(context);
|
||||||
if (event->type == SDL_JOYBUTTONDOWN) {
|
if (event->type == SDL_JOYBUTTONDOWN) {
|
||||||
core->addKeys(core, 1 << key);
|
context->core->addKeys(context->core, 1 << key);
|
||||||
} else {
|
} else {
|
||||||
core->clearKeys(core, 1 << key);
|
context->core->clearKeys(context->core, 1 << key);
|
||||||
}
|
}
|
||||||
|
mCoreThreadContinue(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void _mSDLHandleJoyHat(struct mCore* core, struct mSDLPlayer* sdlContext, const struct SDL_JoyHatEvent* event) {
|
static void _mSDLHandleJoyHat(struct mCoreThread* context, struct mSDLPlayer* sdlContext, const struct SDL_JoyHatEvent* event) {
|
||||||
int allKeys = mInputMapHat(sdlContext->bindings, SDL_BINDING_BUTTON, event->hat, -1);
|
int allKeys = mInputMapHat(sdlContext->bindings, SDL_BINDING_BUTTON, event->hat, -1);
|
||||||
if (allKeys == 0) {
|
if (allKeys == 0) {
|
||||||
return;
|
return;
|
||||||
|
@ -538,11 +542,13 @@ static void _mSDLHandleJoyHat(struct mCore* core, struct mSDLPlayer* sdlContext,
|
||||||
|
|
||||||
int keys = mInputMapHat(sdlContext->bindings, SDL_BINDING_BUTTON, event->hat, event->value);
|
int keys = mInputMapHat(sdlContext->bindings, SDL_BINDING_BUTTON, event->hat, event->value);
|
||||||
|
|
||||||
core->clearKeys(core, allKeys ^ keys);
|
mCoreThreadInterrupt(context);
|
||||||
core->addKeys(core, keys);
|
context->core->clearKeys(context->core, allKeys ^ keys);
|
||||||
|
context->core->addKeys(context->core, keys);
|
||||||
|
mCoreThreadContinue(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void _mSDLHandleJoyAxis(struct mCore* core, struct mSDLPlayer* sdlContext, const struct SDL_JoyAxisEvent* event) {
|
static void _mSDLHandleJoyAxis(struct mCoreThread* context, struct mSDLPlayer* sdlContext, const struct SDL_JoyAxisEvent* event) {
|
||||||
int clearKeys = ~mInputClearAxis(sdlContext->bindings, SDL_BINDING_BUTTON, event->axis, -1);
|
int clearKeys = ~mInputClearAxis(sdlContext->bindings, SDL_BINDING_BUTTON, event->axis, -1);
|
||||||
int newKeys = 0;
|
int newKeys = 0;
|
||||||
int key = mInputMapAxis(sdlContext->bindings, SDL_BINDING_BUTTON, event->axis, event->value);
|
int key = mInputMapAxis(sdlContext->bindings, SDL_BINDING_BUTTON, event->axis, event->value);
|
||||||
|
@ -550,8 +556,10 @@ static void _mSDLHandleJoyAxis(struct mCore* core, struct mSDLPlayer* sdlContext
|
||||||
newKeys |= 1 << key;
|
newKeys |= 1 << key;
|
||||||
}
|
}
|
||||||
clearKeys &= ~newKeys;
|
clearKeys &= ~newKeys;
|
||||||
core->clearKeys(core, clearKeys);
|
mCoreThreadInterrupt(context);
|
||||||
core->addKeys(core, newKeys);
|
context->core->clearKeys(context->core, clearKeys);
|
||||||
|
context->core->addKeys(context->core, newKeys);
|
||||||
|
mCoreThreadContinue(context);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -581,13 +589,13 @@ void mSDLHandleEvent(struct mCoreThread* context, struct mSDLPlayer* sdlContext,
|
||||||
break;
|
break;
|
||||||
case SDL_JOYBUTTONDOWN:
|
case SDL_JOYBUTTONDOWN:
|
||||||
case SDL_JOYBUTTONUP:
|
case SDL_JOYBUTTONUP:
|
||||||
_mSDLHandleJoyButton(context->core, sdlContext, &event->jbutton);
|
_mSDLHandleJoyButton(context, sdlContext, &event->jbutton);
|
||||||
break;
|
break;
|
||||||
case SDL_JOYHATMOTION:
|
case SDL_JOYHATMOTION:
|
||||||
_mSDLHandleJoyHat(context->core, sdlContext, &event->jhat);
|
_mSDLHandleJoyHat(context, sdlContext, &event->jhat);
|
||||||
break;
|
break;
|
||||||
case SDL_JOYAXISMOTION:
|
case SDL_JOYAXISMOTION:
|
||||||
_mSDLHandleJoyAxis(context->core, sdlContext, &event->jaxis);
|
_mSDLHandleJoyAxis(context, sdlContext, &event->jaxis);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue