diff --git a/src/Platform_Web.c b/src/Platform_Web.c index 62020cdf1..e5e1ca413 100644 --- a/src/Platform_Web.c +++ b/src/Platform_Web.c @@ -358,7 +358,12 @@ cc_result Socket_Poll(cc_socket s, int mode, cc_bool* success) { *-----------------------------------------------------Process/Module------------------------------------------------------* *#########################################################################################################################*/ cc_result Process_StartGame(const cc_string* args) { return ERR_NOT_SUPPORTED; } -void Process_Exit(cc_result code) { exit(code); } +void Process_Exit(cc_result code) { + /* Window isn't implicitly closed when process is exited */ + if (code) Window_Close(); + + exit(code); +} extern int interop_OpenTab(const char* url); cc_result Process_StartOpen(const cc_string* args) { diff --git a/src/Window_Web.c b/src/Window_Web.c index 90e96ef1e..917fafdeb 100644 --- a/src/Window_Web.c +++ b/src/Window_Web.c @@ -481,13 +481,16 @@ void Window_Close(void) { WindowInfo.Exists = false; Event_RaiseVoid(&WindowEvents.Closing); /* If the game is closed while in fullscreen, the last rendered frame stays */ - /* shown in fullscreen, but the game can't be interacted with anymore */ + /* shown in fullscreen, but the game can't be interacted with anymore */ Window_ExitFullscreen(); /* Don't want cursor stuck on the dead 0,0 canvas */ Window_DisableRawMouse(); Window_SetSize(0, 0); UnhookEvents(); + /* Game_DoFrame doesn't do anything when WindowExists.False is false, */ + /* but it's still better to cancel main loop to minimise resource usage */ + emscripten_cancel_main_loop(); } extern void interop_RequestCanvasResize(void);