Merge pull request #26955 from tupaschoal/future_hang_download_all

Fix #26056: Freeze when trying to download all objects on save where they are missing
This commit is contained in:
Michael Steenbeek authored and GitHub committed 2026-08-20 20:42:06 +02:00
commit 2449e06d9c
4 files changed
+18 -9

No files matched your search

+1
View File
@@ -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.
+11 -5
View File
@@ -7,6 +7,7 @@
* OpenRCT2 is licensed under the GNU General Public License version 3.
*****************************************************************************/
#include <chrono>
#include <mutex>
#include <openrct2-ui/interface/Widget.h>
#include <openrct2-ui/interface/Window.h>
@@ -68,6 +69,7 @@ namespace OpenRCT2::Ui::Windows
std::mutex _downloadedEntriesMutex;
std::mutex _queueMutex;
bool _nextDownloadQueued{};
std::vector<std::shared_future<void>> _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<ObjectEntryDescriptor>& entries)
{
_pendingRequests.clear();
_lastDownloadStatusInfo = {};
_downloadStatusInfo = {};
_lastDownloadSource = {};
@@ -102,6 +105,10 @@ namespace OpenRCT2::Ui::Windows
void Update()
{
std::erase_if(_pendingRequests, [](const std::shared_future<void>& 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<int32_t>(response.status));
QueueNextDownload();
}
});
}));
}
catch (const std::exception&)
{
+1 -1
View File
@@ -53,7 +53,7 @@ namespace OpenRCT2::Http
Response Do(const Request& req);
inline auto DoAsync(const Request& req, std::function<void(Response& res)> fn)
[[nodiscard]] inline auto DoAsync(const Request& req, std::function<void(Response& res)> fn)
{
return std::async(std::launch::async, [=]() {
Response res{};
+5 -3
View File
@@ -264,7 +264,7 @@ namespace OpenRCT2::Network
}
}
std::future<std::vector<ServerListEntry>> ServerList::FetchLocalServerListAsync(
[[nodiscard]] std::future<std::vector<ServerListEntry>> ServerList::FetchLocalServerListAsync(
const INetworkEndpoint& broadcastEndpoint) const
{
auto broadcastAddress = broadcastEndpoint.GetHostname();
@@ -321,7 +321,7 @@ namespace OpenRCT2::Network
});
}
std::future<std::vector<ServerListEntry>> ServerList::FetchLocalServerListAsync() const
[[nodiscard]] std::future<std::vector<ServerListEntry>> 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
{