From 2b0cc65dba2465218cdfa0e88e37d9f3d11ff203 Mon Sep 17 00:00:00 2001 From: Brad Hughes Date: Wed, 30 Mar 2016 17:24:29 -0400 Subject: [PATCH] Unsubscribe SDL input modules from events on exit. --- src/osd/modules/input/input_sdl.cpp | 8 ++++++++ src/osd/modules/input/input_sdlcommon.h | 10 +++++++--- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/osd/modules/input/input_sdl.cpp b/src/osd/modules/input/input_sdl.cpp index 9ea26733f60..2c5b2e45a8c 100644 --- a/src/osd/modules/input/input_sdl.cpp +++ b/src/osd/modules/input/input_sdl.cpp @@ -435,6 +435,14 @@ public: } } + void exit() override + { + // unsubscribe for events + sdl_event_manager::instance().unsubscribe(this); + + input_module_base::exit(); + } + void before_poll(running_machine& machine) override { // Tell the event manager to process events and push them to the devices diff --git a/src/osd/modules/input/input_sdlcommon.h b/src/osd/modules/input/input_sdlcommon.h index 3650a313e9d..458b90be7ba 100644 --- a/src/osd/modules/input/input_sdlcommon.h +++ b/src/osd/modules/input/input_sdlcommon.h @@ -96,12 +96,16 @@ public: std::lock_guard scope_lock(m_lock); // Loop over the entries and find ones that match our subscriber - // remove those that match - for (auto iter = m_subscription_index.begin(); iter != m_subscription_index.end(); iter++) + std::vector::iterator> remove; + for (auto iter = m_subscription_index.begin(); iter != m_subscription_index.end(); ++iter) { if (iter->second == subscriber) - m_subscription_index.erase(iter); + remove.push_back(iter); } + + // remove those that matched + for (int i = 0; i < remove.size(); i++) + m_subscription_index.erase(remove[i]); } virtual void process_events(running_machine &machine) = 0;