From c995abc25ecff93c8b70d96683e8c9389c40f117 Mon Sep 17 00:00:00 2001 From: Hielke Morsink Date: Sat, 9 Apr 2022 17:42:17 +0200 Subject: [PATCH] Fix: Crash on opening scenery window after removing tabs The crash occurred because gWindowSceneryTabSelections did not get cleared when the window is not open, yet this is a global variable that needs clearing. The function that handles this (WindowSceneryResetSelectedSceneryItems) gets called with the `INTENT_ACTION_REFRESH_SCENERY` intent. --- src/openrct2-ui/windows/Scenery.cpp | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/src/openrct2-ui/windows/Scenery.cpp b/src/openrct2-ui/windows/Scenery.cpp index 7e1a558fde..87d1a8b84b 100644 --- a/src/openrct2-ui/windows/Scenery.cpp +++ b/src/openrct2-ui/windows/Scenery.cpp @@ -730,12 +730,6 @@ public: OnMouseDown(WIDX_SCENERY_TAB_1 + tabId); } - // Used after removing objects, in order to avoid crashes. - void ResetSelectedSceneryItems() - { - gWindowSceneryTabSelections.clear(); - } - void Init() { _tabEntries.clear(); @@ -1383,11 +1377,8 @@ void WindowScenerySetSelectedTab(const ObjectEntryIndex sceneryGroupIndex) // Used after removing objects, in order to avoid crashes. void WindowSceneryResetSelectedSceneryItems() { - auto* w = static_cast(window_find_by_class(WC_SCENERY)); - if (w != nullptr) - { - w->ResetSelectedSceneryItems(); - } + gWindowSceneryTabSelections.clear(); + gWindowSceneryActiveTabIndex = 0; } void WindowScenerySetDefaultPlacementConfiguration() @@ -1397,8 +1388,7 @@ void WindowScenerySetDefaultPlacementConfiguration() gWindowScenerySecondaryColour = COLOUR_YELLOW; gWindowSceneryTertiaryColour = COLOUR_DARK_BROWN; - gWindowSceneryTabSelections.clear(); - gWindowSceneryActiveTabIndex = 0; + WindowSceneryResetSelectedSceneryItems(); } void WindowSceneryInit()