Skip to content

Commit 53da6ba

Browse files
committed
bugfix(w3d): Load background textures when no loader thread is running
ThreadClass::Execute() starts nothing on Unix-like platforms - its _UNIX branch returns immediately - so the web build has no texture loader thread. Everything pushed to the background queue stayed there forever: those textures never finished loading, and the engine kept drawing the missing-texture placeholder, which is why terrain and units came out magenta. Do the loader thread's work from TextureLoader::Update when the thread is not running: pop each background task, Load() it, and hand it to the foreground queue exactly as the thread would. No background lock is taken, because without a second thread there is nobody to contend with. Guarded to Emscripten, so platforms whose loader thread does run are untouched.
1 parent 755d205 commit 53da6ba

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

Core/Libraries/Source/WWVegas/WW3D2/textureloader.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1472,6 +1472,24 @@ void TextureLoader::Update(void (*network_callback)())
14721472
return;
14731473
}
14741474

1475+
#if defined(__EMSCRIPTEN__)
1476+
// TheSuperHackers @bugfix githubawn 30/07/2026 Do the background loader's work here
1477+
// when no loader thread is running. ThreadClass::Execute() starts nothing on Unix-like
1478+
// platforms, so on the web _TextureLoadThread never runs and everything pushed to the
1479+
// background queue stayed there: those textures never finished loading and the engine
1480+
// kept drawing the missing-texture placeholder, which is why terrain and units came out
1481+
// magenta. Same steps the thread would take, minus the background lock - without a
1482+
// second thread there is nobody to contend with.
1483+
if (!_TextureLoadThread.Is_Running()) {
1484+
while (TextureLoadTaskClass* task = _BackgroundQueue.Pop_Front()) {
1485+
WWASSERT(task->Get_Type() == TextureLoadTaskClass::TASK_LOAD);
1486+
WWASSERT(task->Get_State() == TextureLoadTaskClass::STATE_LOAD_BEGUN);
1487+
task->Load();
1488+
_ForegroundQueue.Push_Back(task);
1489+
}
1490+
}
1491+
#endif
1492+
14751493
// grab foreground lock to prevent any other thread from
14761494
// modifying texture tasks.
14771495
FastCriticalSectionClass::LockClass lock(_ForegroundCriticalSection);

0 commit comments

Comments
 (0)