From a8c476a9a2bd1a2fe2854db802610efdcf1f851b Mon Sep 17 00:00:00 2001 From: Garrett Leach <66348375+garrettleach@users.noreply.github.com> Date: Mon, 7 Apr 2025 16:26:10 -0500 Subject: [PATCH] Fix crash from failing to open file for preview (#24171) If the file open fails in FileStream it will throw an IOException. We now capture that exception in the existing catch. --- distribution/changelog.txt | 1 + src/openrct2-ui/windows/ScenarioSelect.cpp | 20 ++++++++++---------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/distribution/changelog.txt b/distribution/changelog.txt index fd2b0db4c2..e52b05ef5e 100644 --- a/distribution/changelog.txt +++ b/distribution/changelog.txt @@ -3,6 +3,7 @@ - Change: [#23803] Lightning strikes and thunder happen at the same frequency independently of the game speed. - Fix: [#21919] Non-recolourable cars still show colour picker. - Fix: [#23108] Missing pieces on Hypercoaster and Hyper-Twister, even with the ‘all drawable track pieces’ cheat enabled. +- Fix: [#24013] Failure to load a scenario preview image (minimap) could lead to an uncaught exception error message. 0.4.21 (2025-04-05) ------------------------------------------------------------------------ diff --git a/src/openrct2-ui/windows/ScenarioSelect.cpp b/src/openrct2-ui/windows/ScenarioSelect.cpp index 08bde9f6bb..5a05351f2a 100644 --- a/src/openrct2-ui/windows/ScenarioSelect.cpp +++ b/src/openrct2-ui/windows/ScenarioSelect.cpp @@ -180,17 +180,17 @@ namespace OpenRCT2::Ui::Windows return; auto& path = _highlightedScenario->Path; - auto fs = FileStream(path, FileMode::open); - - ClassifiedFileInfo info; - if (!TryClassifyFile(&fs, &info) || info.Type != FileType::park) - { - // TODO: try loading a preview from a 'scenario meta' object file - return; - } - try { + auto fs = FileStream(path, FileMode::open); + + ClassifiedFileInfo info; + if (!TryClassifyFile(&fs, &info) || info.Type != FileType::park) + { + // TODO: try loading a preview from a 'scenario meta' object file + return; + } + auto& objectRepository = GetContext()->GetObjectRepository(); auto parkImporter = ParkImporter::CreateParkFile(objectRepository); parkImporter->LoadFromStream(&fs, false, true, path.c_str()); @@ -198,7 +198,7 @@ namespace OpenRCT2::Ui::Windows } catch (const std::exception& e) { - LOG_ERROR("Could not get preview:", e.what()); + LOG_ERROR("Could not get preview for \"%s\" due to %s", path.c_str(), e.what()); _preview = {}; return; }