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] 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; }