From eca89c16bb9a47ad6a2b96842636aa5fd412123a Mon Sep 17 00:00:00 2001 From: Xenius97 Date: Mon, 17 Nov 2025 10:20:24 +0100 Subject: [PATCH 1/4] Fix crash when game is shutting down When game shuts down there is no reason to do anything with images --- Client/mods/deathmatch/logic/CClientIMG.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Client/mods/deathmatch/logic/CClientIMG.cpp b/Client/mods/deathmatch/logic/CClientIMG.cpp index 91443a87aba..1a7fe7e19bb 100644 --- a/Client/mods/deathmatch/logic/CClientIMG.cpp +++ b/Client/mods/deathmatch/logic/CClientIMG.cpp @@ -174,7 +174,8 @@ bool CClientIMG::StreamEnable() bool CClientIMG::StreamDisable() { - if (!IsStreamed()) + // If game is shutting down or not streaming is not available, do nothing + if (!g_pClientGame || !g_pGame || !g_pGame->GetStreaming()) return false; // Unlink all models From 72823a90db8558ad7f98adc424679ae0d037c947 Mon Sep 17 00:00:00 2001 From: Xenius97 Date: Mon, 17 Nov 2025 10:34:35 +0100 Subject: [PATCH 2/4] Add shutdown flag to prevent streaming during client shutdown --- Client/mods/deathmatch/CClient.cpp | 4 ++++ Client/mods/deathmatch/CClient.h | 2 ++ Client/mods/deathmatch/logic/CClientIMG.cpp | 2 +- 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/Client/mods/deathmatch/CClient.cpp b/Client/mods/deathmatch/CClient.cpp index f44830fcb2a..b2c24f8aca9 100644 --- a/Client/mods/deathmatch/CClient.cpp +++ b/Client/mods/deathmatch/CClient.cpp @@ -20,6 +20,7 @@ CGame* g_pGame = NULL; CMultiplayer* g_pMultiplayer = NULL; CNet* g_pNet = NULL; CClientGame* g_pClientGame = NULL; +bool g_bClientShuttingDown = false; int CClient::ClientInitialize(const char* szArguments, CCoreInterface* pCore) { @@ -183,6 +184,9 @@ int CClient::ClientInitialize(const char* szArguments, CCoreInterface* pCore) void CClient::ClientShutdown() { + // Global shutdown flag + g_bClientShuttingDown = true; + // Unbind our radio controls g_pCore->GetKeyBinds()->RemoveControlFunction("radio_next", CClientGame::HandleRadioNext); g_pCore->GetKeyBinds()->RemoveControlFunction("radio_previous", CClientGame::HandleRadioPrevious); diff --git a/Client/mods/deathmatch/CClient.h b/Client/mods/deathmatch/CClient.h index af34d09e005..132cec1be14 100644 --- a/Client/mods/deathmatch/CClient.h +++ b/Client/mods/deathmatch/CClient.h @@ -13,6 +13,8 @@ #include +extern bool g_bClientShuttingDown; + class CClient : public CClientBase { public: diff --git a/Client/mods/deathmatch/logic/CClientIMG.cpp b/Client/mods/deathmatch/logic/CClientIMG.cpp index 1a7fe7e19bb..485405977d3 100644 --- a/Client/mods/deathmatch/logic/CClientIMG.cpp +++ b/Client/mods/deathmatch/logic/CClientIMG.cpp @@ -175,7 +175,7 @@ bool CClientIMG::StreamEnable() bool CClientIMG::StreamDisable() { // If game is shutting down or not streaming is not available, do nothing - if (!g_pClientGame || !g_pGame || !g_pGame->GetStreaming()) + if (g_bClientShuttingDown || !IsStreamed()) return false; // Unlink all models From 72d3bae57219e9f842655cc6f207dbe53aac7690 Mon Sep 17 00:00:00 2001 From: Xenius97 Date: Sat, 22 Nov 2025 23:00:06 +0100 Subject: [PATCH 3/4] Prevent unnecessary operations during game shutdown in RestreamWorld and StreamDisable --- Client/mods/deathmatch/logic/CClientGame.cpp | 4 ++++ Client/mods/deathmatch/logic/CClientIMG.cpp | 3 +-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/Client/mods/deathmatch/logic/CClientGame.cpp b/Client/mods/deathmatch/logic/CClientGame.cpp index f07ac565c82..f8efe75a94b 100644 --- a/Client/mods/deathmatch/logic/CClientGame.cpp +++ b/Client/mods/deathmatch/logic/CClientGame.cpp @@ -6851,6 +6851,10 @@ bool CClientGame::RestreamModel(std::uint16_t model) void CClientGame::RestreamWorld() { + // If game is shutting down or not streaming is not available, do nothing + if (g_bClientShuttingDown) + return; + unsigned int numberOfFileIDs = g_pGame->GetCountOfAllFileIDs(); for (unsigned int uiModelID = 0; uiModelID < numberOfFileIDs; uiModelID++) diff --git a/Client/mods/deathmatch/logic/CClientIMG.cpp b/Client/mods/deathmatch/logic/CClientIMG.cpp index 485405977d3..91443a87aba 100644 --- a/Client/mods/deathmatch/logic/CClientIMG.cpp +++ b/Client/mods/deathmatch/logic/CClientIMG.cpp @@ -174,8 +174,7 @@ bool CClientIMG::StreamEnable() bool CClientIMG::StreamDisable() { - // If game is shutting down or not streaming is not available, do nothing - if (g_bClientShuttingDown || !IsStreamed()) + if (!IsStreamed()) return false; // Unlink all models From b4aba044b3eb6f1966d0181d5859897fa3513818 Mon Sep 17 00:00:00 2001 From: Xenius97 Date: Sat, 22 Nov 2025 23:01:32 +0100 Subject: [PATCH 4/4] Clarify shutdown condition in RestreamWorld function comment --- Client/mods/deathmatch/logic/CClientGame.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Client/mods/deathmatch/logic/CClientGame.cpp b/Client/mods/deathmatch/logic/CClientGame.cpp index f8efe75a94b..796c8876658 100644 --- a/Client/mods/deathmatch/logic/CClientGame.cpp +++ b/Client/mods/deathmatch/logic/CClientGame.cpp @@ -6851,7 +6851,7 @@ bool CClientGame::RestreamModel(std::uint16_t model) void CClientGame::RestreamWorld() { - // If game is shutting down or not streaming is not available, do nothing + // If game is shutting down, do nothing for avoid crashes if (g_bClientShuttingDown) return;