From 4cce29b5a9aceb14321ef7350457a17e896adf16 Mon Sep 17 00:00:00 2001 From: Tulio Leao Date: Wed, 19 Aug 2026 21:28:15 -0300 Subject: [PATCH 1/2] Fix #26056: Freeze when trying to download all objects on save where they are missing --- distribution/changelog.txt | 1 + src/openrct2-ui/windows/ObjectLoadError.cpp | 16 +++++++++++----- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/distribution/changelog.txt b/distribution/changelog.txt index 6b43859ced..dad2b2049f 100644 --- a/distribution/changelog.txt +++ b/distribution/changelog.txt @@ -13,6 +13,7 @@ - Fix: [#25169] The convert command strips custom objects from the resulting park. - Fix: [#25496] The guest pickup button does not grey out when the guest’s state changes while the window is open. - Fix: [#25558] [Plugin] Image buttons ignore their explicit border setting when a theme draws borders around them. +- Fix: [#26056] Freeze when trying to download all objects on save where they are missing. - Fix: [#26811] Crash when a ride points to a non-existing station object. - Fix: [#26816] Water rides ignore zero clearances, preventing adjacent terrain modifications and building them anywhere. - Fix: [#26880] Max negative G-Force stat on flat track erroneously reads as 0.49g. diff --git a/src/openrct2-ui/windows/ObjectLoadError.cpp b/src/openrct2-ui/windows/ObjectLoadError.cpp index d312ca4c0b..2e78b0dc00 100644 --- a/src/openrct2-ui/windows/ObjectLoadError.cpp +++ b/src/openrct2-ui/windows/ObjectLoadError.cpp @@ -7,6 +7,7 @@ * OpenRCT2 is licensed under the GNU General Public License version 3. *****************************************************************************/ +#include #include #include #include @@ -68,6 +69,7 @@ namespace OpenRCT2::Ui::Windows std::mutex _downloadedEntriesMutex; std::mutex _queueMutex; bool _nextDownloadQueued{}; + std::vector> _pendingRequests; // Store futures to prevent blocking destructors DownloadStatusInfo _lastDownloadStatusInfo; DownloadStatusInfo _downloadStatusInfo; @@ -80,6 +82,7 @@ namespace OpenRCT2::Ui::Windows public: void Begin(const std::vector& entries) { + _pendingRequests.clear(); _lastDownloadStatusInfo = {}; _downloadStatusInfo = {}; _lastDownloadSource = {}; @@ -102,6 +105,10 @@ namespace OpenRCT2::Ui::Windows void Update() { + std::erase_if(_pendingRequests, [](const std::shared_future& f) { + return f.wait_for(std::chrono::seconds::zero()) == std::future_status::ready; + }); + std::lock_guard guard(_queueMutex); if (_nextDownloadQueued) { @@ -169,11 +176,10 @@ namespace OpenRCT2::Ui::Windows { try { - Console::WriteLine("Downloading %s", url.c_str()); Http::Request req; req.method = Http::Method::get; req.url = url; - Http::DoAsync(req, [this, entry, name](Http::Response response) { + _pendingRequests.push_back(Http::DoAsync(req, [this, entry, name](Http::Response response) { if (response.status == Http::Status::ok) { // Check that download operation hasn't been cancelled @@ -194,7 +200,7 @@ namespace OpenRCT2::Ui::Windows Console::Error::WriteLine(" Failed to download %s", name.c_str()); } QueueNextDownload(); - }); + })); } catch (const std::exception&) { @@ -223,7 +229,7 @@ namespace OpenRCT2::Ui::Windows Http::Request req; req.method = Http::Method::get; req.url = kOpenRCT2ApiLegacyObjectURL + name; - Http::DoAsync(req, [this, entry, name](Http::Response response) { + _pendingRequests.push_back(Http::DoAsync(req, [this, entry, name](Http::Response response) { if (response.status == Http::Status::ok) { auto jresponse = Json::FromString(response.body); @@ -251,7 +257,7 @@ namespace OpenRCT2::Ui::Windows " %s query failed (status %d)", name.c_str(), static_cast(response.status)); QueueNextDownload(); } - }); + })); } catch (const std::exception&) { From 44b178e30f6b072ba86ca7a6edacf4a09054858f Mon Sep 17 00:00:00 2001 From: Tulio Leao Date: Wed, 19 Aug 2026 22:25:47 -0300 Subject: [PATCH 2/2] Make all places returning std::async [[nodiscard]] --- src/openrct2/core/Http.h | 2 +- src/openrct2/network/ServerList.cpp | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/openrct2/core/Http.h b/src/openrct2/core/Http.h index d4cc30b5ba..cd80723302 100644 --- a/src/openrct2/core/Http.h +++ b/src/openrct2/core/Http.h @@ -53,7 +53,7 @@ namespace OpenRCT2::Http Response Do(const Request& req); - inline auto DoAsync(const Request& req, std::function fn) + [[nodiscard]] inline auto DoAsync(const Request& req, std::function fn) { return std::async(std::launch::async, [=]() { Response res{}; diff --git a/src/openrct2/network/ServerList.cpp b/src/openrct2/network/ServerList.cpp index fb36c63aea..b37905be3e 100644 --- a/src/openrct2/network/ServerList.cpp +++ b/src/openrct2/network/ServerList.cpp @@ -264,7 +264,7 @@ namespace OpenRCT2::Network } } - std::future> ServerList::FetchLocalServerListAsync( + [[nodiscard]] std::future> ServerList::FetchLocalServerListAsync( const INetworkEndpoint& broadcastEndpoint) const { auto broadcastAddress = broadcastEndpoint.GetHostname(); @@ -321,7 +321,7 @@ namespace OpenRCT2::Network }); } - std::future> ServerList::FetchLocalServerListAsync() const + [[nodiscard]] std::future> ServerList::FetchLocalServerListAsync() const { return std::async(std::launch::async, [&] { // Get all possible LAN broadcast addresses @@ -372,7 +372,9 @@ namespace OpenRCT2::Network request.url = std::move(masterServerUrl); request.method = Http::Method::get; request.header["Accept"] = "application/json"; - Http::DoAsync(request, [p](Http::Response& response) -> void { + // Despite DoAsync, the future below is not stored, so it will block the calling thread until the request completes + // TOOD: Review if this is acceptable + std::ignore = Http::DoAsync(request, [p](Http::Response& response) -> void { json_t root; try {