Skip to content

Commit 27dfd86

Browse files
committed
bugfix(web): Yield to the browser event loop at the multiplayer load barrier
startNewGame waits for every player's "load complete" message in a while(!isProgressComplete()) Sleep(100) loop. In a browser those messages arrive through WebSocket callbacks that only run when control returns to the event loop, which Sleep() never does, so starting a multiplayer match hung here forever. Call emscripten_sleep() instead on Emscripten, which yields cooperatively. The link already enables the ASYNCIFY this needs - its flag was carried over without the call site that motivated it.
1 parent 53da6ba commit 27dfd86

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@
2929

3030
#include "PreRTS.h" // This must go first in EVERY cpp file in the GameEngine
3131

32+
#if defined(__EMSCRIPTEN__)
33+
#include <emscripten.h> // for emscripten_sleep() in the multiplayer load barrier below
34+
#endif
35+
3236
#include "Common/AudioAffect.h"
3337
#include "Common/AudioHandleSpecialValues.h"
3438
#include "Common/BuildAssistant.h"
@@ -2627,7 +2631,17 @@ void GameLogic::tryStartNewGame( Bool loadingSaveGame )
26272631
{
26282632
updateLoadProgress(101); // keep greater then 100
26292633
testTimeOut();
2634+
// TheSuperHackers @bugfix githubawn 30/07/2026 On the web the other players'
2635+
// "load complete" messages arrive through WebSocket callbacks that only fire when
2636+
// control returns to the browser's event loop. Sleep() never yields to it, so this
2637+
// barrier could never be satisfied and starting a multiplayer match hung here.
2638+
// emscripten_sleep() yields cooperatively (the ASYNCIFY the link already enables),
2639+
// letting those messages land and isProgressComplete() become true.
2640+
#if defined(__EMSCRIPTEN__)
2641+
emscripten_sleep(100);
2642+
#else
26302643
Sleep(100);
2644+
#endif
26312645
}
26322646

26332647
while(m_loadScreen && !m_loadScreen->isReadyForGameStart())

0 commit comments

Comments
 (0)