From bb6182bafbf247e471428ff0acca1e435ad53f93 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Janiszewski?= Date: Sun, 26 Mar 2023 23:36:36 +0200 Subject: [PATCH 1/4] Fix closing invention list window while holding invention Calling `Close()` on a window deletes its object, rendering any future uses of its members invalid. This can be triggered by opening inventions list window, holding an invention, closing the inventions list window (e.g. with keyboard) and then releasing the held invention --- src/openrct2-ui/windows/EditorInventionsList.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/openrct2-ui/windows/EditorInventionsList.cpp b/src/openrct2-ui/windows/EditorInventionsList.cpp index 76cc8a1b9d..749c605b99 100644 --- a/src/openrct2-ui/windows/EditorInventionsList.cpp +++ b/src/openrct2-ui/windows/EditorInventionsList.cpp @@ -619,6 +619,7 @@ public: if (inventionListWindow == nullptr) { Close(); + return; } std::optional res; // Skip always researched items, so that the dragged item gets placed underneath them From 1670de0a4edbfe20f604d82a1ee2f00785e732fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Janiszewski?= Date: Sun, 26 Mar 2023 23:39:59 +0200 Subject: [PATCH 2/4] Fix guest window accessing members after it is deleted Calling `Close()` on a window deletes its object, rendering any future uses of its members invalid. --- src/openrct2-ui/windows/Guest.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/openrct2-ui/windows/Guest.cpp b/src/openrct2-ui/windows/Guest.cpp index df87dc5461..609197f2c1 100644 --- a/src/openrct2-ui/windows/Guest.cpp +++ b/src/openrct2-ui/windows/Guest.cpp @@ -207,7 +207,7 @@ public: { case WIDX_CLOSE: Close(); - break; + return; case WIDX_TAB_1: case WIDX_TAB_2: case WIDX_TAB_3: @@ -216,7 +216,7 @@ public: case WIDX_TAB_6: case WIDX_TAB_7: SetPage(widx - WIDX_TAB_1); - break; + return; } switch (page) From be82582063019e408123317e73af71f553c8103c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Janiszewski?= Date: Mon, 27 Mar 2023 23:48:43 +0200 Subject: [PATCH 3/4] Fix EditorObjectSelection opening of TrackManager Calling `Close()` on a window deletes its object, rendering any future uses of its members invalid. In this case `WindowsCloseAll` closed Editor window itself rendering call to `ManageTracks` on a deleted pointer. Previously `WindowsCloseAll` was called, but earlier in the same function we have already closed all windows but Editor itself. It is sufficient to close the editor once we have opened `TrackDesignList`. When this got fixed, I noticed `TrackDesignList` could not locate any rides, which was happening due to calls to `ObjectManager::UnloadAll` in several places. Code to load the selected ride back was added. --- src/openrct2-ui/windows/EditorObjectSelection.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/openrct2-ui/windows/EditorObjectSelection.cpp b/src/openrct2-ui/windows/EditorObjectSelection.cpp index 2c8ea108b1..4b0e51ea84 100644 --- a/src/openrct2-ui/windows/EditorObjectSelection.cpp +++ b/src/openrct2-ui/windows/EditorObjectSelection.cpp @@ -599,12 +599,14 @@ public: if (!objectSelectResult.Successful) return; - // Close any other open windows such as options/colour schemes to prevent a crash. - WindowCloseAll(); - // WindowClose(*w); + auto& objRepository = OpenRCT2::GetContext()->GetObjectRepository(); + _loadedObject = objRepository.LoadObject(listItem->repositoryItem); + auto& objManager = OpenRCT2::GetContext()->GetObjectManager(); + objManager.LoadObject(_loadedObject.get()->GetIdentifier()); // This function calls window_track_list_open ManageTracks(); + Close(); return; } From 56ff06a8d25628a30ea1031cf37c27ac6663f7d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Janiszewski?= Date: Mon, 27 Mar 2023 23:55:09 +0200 Subject: [PATCH 4/4] Fix the object editor tab selector Object editor has unusually high WIDX_TAB_1 value making the default 32-bit type not wide enough. --- src/openrct2-ui/windows/EditorObjectSelection.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/openrct2-ui/windows/EditorObjectSelection.cpp b/src/openrct2-ui/windows/EditorObjectSelection.cpp index 4b0e51ea84..47d565b310 100644 --- a/src/openrct2-ui/windows/EditorObjectSelection.cpp +++ b/src/openrct2-ui/windows/EditorObjectSelection.cpp @@ -1487,7 +1487,7 @@ private: { for (size_t i = 0; i < std::size(ObjectSelectionPages); i++) { - pressed_widgets &= ~(1 << (WIDX_TAB_1 + i)); + pressed_widgets &= ~(1ull << (WIDX_TAB_1 + i)); } pressed_widgets |= 1LL << (WIDX_TAB_1 + selected_tab); }