diff options
author | StapleButter <thetotalworm@gmail.com> | 2018-12-29 23:32:58 +0100 |
---|---|---|
committer | StapleButter <thetotalworm@gmail.com> | 2018-12-29 23:32:58 +0100 |
commit | 65c27c5c288818193d7957ae3549d687ccafaec5 (patch) | |
tree | c8e8361308d3bcc853abe3de93c4f912e8a62b5d | |
parent | 5c5146945cf0527050caa2eeedf0aba5da8febe8 (diff) |
fix potential crashes in input config dialog when setting joystick buttons, by using uiQueueMain()
how could I not think of this? GTK is not thread safe.
-rw-r--r-- | src/libui_sdl/DlgInputConfig.cpp | 35 |
1 files changed, 17 insertions, 18 deletions
diff --git a/src/libui_sdl/DlgInputConfig.cpp b/src/libui_sdl/DlgInputConfig.cpp index 287d7e3..0fc7f4a 100644 --- a/src/libui_sdl/DlgInputConfig.cpp +++ b/src/libui_sdl/DlgInputConfig.cpp @@ -165,6 +165,21 @@ int OnAreaKeyEvent(uiAreaHandler* handler, uiArea* area, uiAreaKeyEvent* evt) return 1; } +void FinishJoyMapping(void* param) +{ + InputDlgData* dlg = (InputDlgData*)param; + int id = dlg->pollid & 0xFF; + + char keyname[16]; + JoyMappingName(dlg->joymap[id], keyname); + uiButtonSetText(dlg->pollbtn, keyname); + uiControlEnable(uiControl(dlg->pollbtn)); + + dlg->pollid = -1; + + uiControlSetFocus(uiControl(dlg->pollbtn)); +} + Uint32 JoyPoll(Uint32 interval, void* param) { InputDlgData* dlg = (InputDlgData*)param; @@ -184,15 +199,7 @@ Uint32 JoyPoll(Uint32 interval, void* param) if (SDL_JoystickGetButton(joy, i)) { dlg->joymap[id] = i; - - char keyname[16]; - JoyMappingName(dlg->joymap[id], keyname); - uiButtonSetText(dlg->pollbtn, keyname); - uiControlEnable(uiControl(dlg->pollbtn)); - - dlg->pollid = -1; - - uiControlSetFocus(uiControl(dlg->pollbtn)); + uiQueueMain(FinishJoyMapping, dlg); return 0; } } @@ -206,15 +213,7 @@ Uint32 JoyPoll(Uint32 interval, void* param) else blackhat = 0x8; dlg->joymap[id] = 0x100 | blackhat; - - char keyname[16]; - JoyMappingName(dlg->joymap[id], keyname); - uiButtonSetText(dlg->pollbtn, keyname); - uiControlEnable(uiControl(dlg->pollbtn)); - - dlg->pollid = -1; - - uiControlSetFocus(uiControl(dlg->pollbtn)); + uiQueueMain(FinishJoyMapping, dlg); return 0; } |