From db4a40a4e66cb2801455b1cb7392ecfc562820de Mon Sep 17 00:00:00 2001 From: Kelsi Date: Fri, 6 Feb 2026 18:40:09 -0800 Subject: [PATCH] Avoid online loading hang on stalled terrain streaming --- src/core/application.cpp | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/core/application.cpp b/src/core/application.cpp index 0d0d49e7..085e0261 100644 --- a/src/core/application.cpp +++ b/src/core/application.cpp @@ -1982,9 +1982,12 @@ void Application::loadOnlineWorldTerrain(uint32_t mapId, float x, float y, float terrainMgr->update(*camera, 1.0f); auto startTime = std::chrono::high_resolution_clock::now(); - const float maxWaitSeconds = 30.0f; + auto lastProgressTime = startTime; + const float maxWaitSeconds = 20.0f; + const float stallSeconds = 5.0f; int initialRemaining = terrainMgr->getRemainingTileCount(); if (initialRemaining < 1) initialRemaining = 1; + int lastRemaining = initialRemaining; // Wait until all pending + ready-queue tiles are finalized while (terrainMgr->getRemainingTileCount() > 0) { @@ -2024,6 +2027,11 @@ void Application::loadOnlineWorldTerrain(uint32_t mapId, float x, float y, float loadingScreen.setProgress(progress); loadingScreen.render(); window->swapBuffers(); + + if (remaining != lastRemaining) { + lastRemaining = remaining; + lastProgressTime = std::chrono::high_resolution_clock::now(); + } } auto elapsed = std::chrono::high_resolution_clock::now() - startTime; @@ -2031,6 +2039,12 @@ void Application::loadOnlineWorldTerrain(uint32_t mapId, float x, float y, float LOG_WARNING("Online terrain streaming timeout after ", maxWaitSeconds, "s"); break; } + auto stalledFor = std::chrono::high_resolution_clock::now() - lastProgressTime; + if (std::chrono::duration(stalledFor).count() > stallSeconds) { + LOG_WARNING("Online terrain streaming stalled for ", stallSeconds, + "s (remaining=", lastRemaining, "), continuing without full preload"); + break; + } SDL_Delay(16); }