summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
author hap <happppp@users.noreply.github.com>2021-01-27 20:13:11 +0100
committer hap <happppp@users.noreply.github.com>2021-01-27 20:13:25 +0100
commit0cd6c079c935152f6ce84351648311ce74f4fb6e (patch)
tree02599cea421ebdb87567dd5d11ce1a395f239c2d
parent7812e9ebb67c314d7cfb616c3f2cde4b916b4668 (diff)
ui/inputmap: prevent race condition between ui_input().pressed() and poll()
-rw-r--r--src/frontend/mame/ui/inputmap.cpp8
-rw-r--r--src/frontend/mame/ui/inputmap.h1
2 files changed, 8 insertions, 1 deletions
diff --git a/src/frontend/mame/ui/inputmap.cpp b/src/frontend/mame/ui/inputmap.cpp
index 94643849893..a1bba50822e 100644
--- a/src/frontend/mame/ui/inputmap.cpp
+++ b/src/frontend/mame/ui/inputmap.cpp
@@ -245,6 +245,7 @@ menu_input::menu_input(mame_ui_manager &mui, render_container &container)
, erroritem(nullptr)
, lastitem(nullptr)
, record_next(false)
+ , modified_ticks(0)
{
}
@@ -322,11 +323,15 @@ void menu_input::handle()
// if we are polling, handle as a special case
input_item_data *const item = pollingitem;
+ // prevent race condition between ui_input().pressed() and poll()
+ if (modified_ticks == 0 && seq_poll->modified())
+ modified_ticks = osd_ticks();
+
if (machine().ui_input().pressed(IPT_UI_CANCEL))
{
// if UI_CANCEL is pressed, abort
pollingitem = nullptr;
- if (!seq_poll->modified())
+ if (!seq_poll->modified() || modified_ticks == osd_ticks())
{
// cancelled immediately - toggle between default and none
record_next = false;
@@ -368,6 +373,7 @@ void menu_input::handle()
case IPT_UI_SELECT: // an item was selected: begin polling
errormsg.clear();
erroritem = nullptr;
+ modified_ticks = 0;
pollingitem = &item;
lastitem = &item;
starting_seq = item.seq;
diff --git a/src/frontend/mame/ui/inputmap.h b/src/frontend/mame/ui/inputmap.h
index bdc1449c89b..5ed8c057c96 100644
--- a/src/frontend/mame/ui/inputmap.h
+++ b/src/frontend/mame/ui/inputmap.h
@@ -75,6 +75,7 @@ private:
input_item_data *erroritem;
input_item_data *lastitem;
bool record_next;
+ osd_ticks_t modified_ticks;
input_seq starting_seq;
virtual void custom_render(void *selectedref, float top, float bottom, float x1, float y1, float x2, float y2) override;