Avoid online loading hang on stalled terrain streaming

This commit is contained in:
Kelsi 2026-02-06 18:40:09 -08:00
parent fdc614902b
commit db4a40a4e6

View file

@ -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<float>(stalledFor).count() > stallSeconds) {
LOG_WARNING("Online terrain streaming stalled for ", stallSeconds,
"s (remaining=", lastRemaining, "), continuing without full preload");
break;
}
SDL_Delay(16);
}