From 4f5fe8d7670d5ae85c8903355b7d3de2501ff1fa Mon Sep 17 00:00:00 2001 From: "seer-by-sentry[bot]" <157164994+seer-by-sentry[bot]@users.noreply.github.com> Date: Sun, 16 Nov 2025 20:42:52 +0000 Subject: [PATCH] Fix: Delay critical section cleanup to prevent static destructor crashes --- Generals/Code/Main/WinMain.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/Generals/Code/Main/WinMain.cpp b/Generals/Code/Main/WinMain.cpp index a5bf5a363dd..35df3c2871e 100644 --- a/Generals/Code/Main/WinMain.cpp +++ b/Generals/Code/Main/WinMain.cpp @@ -853,10 +853,14 @@ Int APIENTRY WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, } - TheAsciiStringCriticalSection = NULL; - TheUnicodeStringCriticalSection = NULL; - TheDmaCriticalSection = NULL; - TheMemoryPoolCriticalSection = NULL; + // TheSuperHackers @bugfix Sentry 05/01/2025 Don't set critical sections to NULL before static destructors run. + // Static objects like TheWritableGlobalData contain AsciiString members that need the critical sections + // during their destruction. The critical section objects (critSec1-5) are static locals and will be + // destroyed automatically after this function returns, which is the correct cleanup order. + // TheAsciiStringCriticalSection = NULL; + // TheUnicodeStringCriticalSection = NULL; + // TheDmaCriticalSection = NULL; + // TheMemoryPoolCriticalSection = NULL; return exitcode;