From c457de1ecec3cb1bd9d0747d6883c51224e122ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=CE=B6eh=20Matt?= Date: Thu, 20 Dec 2018 22:25:10 +0100 Subject: [PATCH] Fix #8402: prevent dereferencing invalid iterator (#8504) --- distribution/changelog.txt | 1 + src/openrct2-ui/input/MouseInput.cpp | 8 ++++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/distribution/changelog.txt b/distribution/changelog.txt index f94aa657b5..691e712f44 100644 --- a/distribution/changelog.txt +++ b/distribution/changelog.txt @@ -39,6 +39,7 @@ - Fix: [#8204] Crash when tile element has no surface elements. - Fix: [#8335] Rides with arbitrary ride types can crash the game when they break down. - Fix: [#8358] Infinite loop when changing vehicle count on stopped ride. +- Fix: [#8402] Crash closing a window in some cases. - Fix: [#8431] Crash when game action logging is enabled. - Fix: [#8433] Crash if master server response is not valid JSON. - Fix: [#8434] Crash if curl_easy_init fails. diff --git a/src/openrct2-ui/input/MouseInput.cpp b/src/openrct2-ui/input/MouseInput.cpp index 059676227c..93038bfd52 100644 --- a/src/openrct2-ui/input/MouseInput.cpp +++ b/src/openrct2-ui/input/MouseInput.cpp @@ -105,8 +105,10 @@ static void input_update_tooltip(rct_window* w, rct_widgetindex widgetIndex, int */ void game_handle_input() { - for (auto& w : g_window_list) + // NOTE: g_window_list may change during the event callbacks. + for (size_t i = g_window_list.size(); i > 0; i--) { + auto& w = g_window_list[i - 1]; window_event_unknown_07_call(w.get()); } @@ -134,8 +136,10 @@ void game_handle_input() process_mouse_tool(x, y); } - for (auto& w : g_window_list) + // NOTE: g_window_list may change during the event callbacks. + for (size_t i = g_window_list.size(); i > 0; i--) { + auto& w = g_window_list[i - 1]; window_event_unknown_08_call(w.get()); } }