From dd67c2971d4f41267d4d08ebd8c5aefdb675c6e5 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Thu, 3 Dec 2015 22:27:01 +0100 Subject: api/joy: fix race erase from iterator referenced the wrong 'joys' variable --- opentrack/win32-joystick.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'opentrack') diff --git a/opentrack/win32-joystick.cpp b/opentrack/win32-joystick.cpp index 6e64355c..0f8a08f8 100644 --- a/opentrack/win32-joystick.cpp +++ b/opentrack/win32-joystick.cpp @@ -222,7 +222,7 @@ win32_joy_ctx::enum_state::enum_state(std::unordered_mapjoys = joys; } - + if(FAILED(hr = di->EnumDevices(DI8DEVCLASS_GAMECTRL, EnumJoysticksCallback, this, @@ -232,10 +232,12 @@ win32_joy_ctx::enum_state::enum_state(std::unordered_mapjoys.begin(); it != this->joys.end(); ) + auto& js = this->joys; + + for (auto it = js.begin(); it != js.end(); ) { if (std::find_if(all.cbegin(), all.cend(), [&](const QString& guid2) -> bool { return it->second->guid == guid2; }) == all.cend()) - it = joys.erase(it); + it = js.erase(it); else it++; } -- cgit v1.2.3