From 1a678a1d7f7a9b246ea9b69e93b964d07fafbc1c Mon Sep 17 00:00:00 2001 From: xezon <4720891+xezon@users.noreply.github.com> Date: Tue, 15 Jul 2025 22:15:52 +0200 Subject: [PATCH 1/2] [ZH] Fix Null Memory Manager issues introduced by #1275 --- .../GameEngine/Source/Common/System/GameMemoryNull.cpp | 7 ++++++- GeneralsMD/Code/Main/WinMain.cpp | 6 +++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/GeneralsMD/Code/GameEngine/Source/Common/System/GameMemoryNull.cpp b/GeneralsMD/Code/GameEngine/Source/Common/System/GameMemoryNull.cpp index cbf029dd5aa..2bfdf80500a 100644 --- a/GeneralsMD/Code/GameEngine/Source/Common/System/GameMemoryNull.cpp +++ b/GeneralsMD/Code/GameEngine/Source/Common/System/GameMemoryNull.cpp @@ -111,10 +111,13 @@ void initMemoryManager() { TheMemoryPoolFactory = new (malloc(sizeof MemoryPoolFactory)) MemoryPoolFactory; TheDynamicMemoryAllocator = new (malloc(sizeof DynamicMemoryAllocator)) DynamicMemoryAllocator; + + DEBUG_INIT(DEBUG_FLAGS_DEFAULT); + DEBUG_LOG(("*** Initialized the Null Memory Manager")); } else { - DEBUG_CRASH(("memory manager is already inited")); + DEBUG_CRASH(("Null Memory Manager is already initialized")); } theMainInitFlag = true; @@ -148,6 +151,8 @@ void shutdownMemoryManager() } theMainInitFlag = false; + + DEBUG_SHUTDOWN(); } diff --git a/GeneralsMD/Code/Main/WinMain.cpp b/GeneralsMD/Code/Main/WinMain.cpp index 6f7d9d663ee..a600d90618b 100644 --- a/GeneralsMD/Code/Main/WinMain.cpp +++ b/GeneralsMD/Code/Main/WinMain.cpp @@ -779,6 +779,9 @@ Int APIENTRY WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, TheMemoryPoolCriticalSection = &critSec4; TheDebugLogCriticalSection = &critSec5; + // initialize the memory manager early + initMemoryManager(); + /// @todo remove this force set of working directory later Char buffer[ _MAX_PATH ]; GetModuleFileName( NULL, buffer, sizeof( buffer ) ); @@ -833,9 +836,6 @@ Int APIENTRY WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, gLoadScreenBitmap = (HBITMAP)LoadImage(hInstance, "Install_Final.bmp", IMAGE_BITMAP, 0, 0, LR_SHARED|LR_LOADFROMFILE); #endif - // initialize the memory manager early - initMemoryManager(); - CommandLine::parseCommandLineForStartup(); // register windows class and create application window From c7d92dc4e1e030a578d3d834b13bea88868ff39b Mon Sep 17 00:00:00 2001 From: xezon <4720891+xezon@users.noreply.github.com> Date: Tue, 15 Jul 2025 22:17:54 +0200 Subject: [PATCH 2/2] Replicate in Generals --- .../GameEngine/Source/Common/System/GameMemoryNull.cpp | 7 ++++++- Generals/Code/Main/WinMain.cpp | 6 +++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/Generals/Code/GameEngine/Source/Common/System/GameMemoryNull.cpp b/Generals/Code/GameEngine/Source/Common/System/GameMemoryNull.cpp index cbf029dd5aa..2bfdf80500a 100644 --- a/Generals/Code/GameEngine/Source/Common/System/GameMemoryNull.cpp +++ b/Generals/Code/GameEngine/Source/Common/System/GameMemoryNull.cpp @@ -111,10 +111,13 @@ void initMemoryManager() { TheMemoryPoolFactory = new (malloc(sizeof MemoryPoolFactory)) MemoryPoolFactory; TheDynamicMemoryAllocator = new (malloc(sizeof DynamicMemoryAllocator)) DynamicMemoryAllocator; + + DEBUG_INIT(DEBUG_FLAGS_DEFAULT); + DEBUG_LOG(("*** Initialized the Null Memory Manager")); } else { - DEBUG_CRASH(("memory manager is already inited")); + DEBUG_CRASH(("Null Memory Manager is already initialized")); } theMainInitFlag = true; @@ -148,6 +151,8 @@ void shutdownMemoryManager() } theMainInitFlag = false; + + DEBUG_SHUTDOWN(); } diff --git a/Generals/Code/Main/WinMain.cpp b/Generals/Code/Main/WinMain.cpp index 55968ebb46d..809a5f85a7b 100644 --- a/Generals/Code/Main/WinMain.cpp +++ b/Generals/Code/Main/WinMain.cpp @@ -753,6 +753,9 @@ Int APIENTRY WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, TheMemoryPoolCriticalSection = &critSec4; TheDebugLogCriticalSection = &critSec5; + // initialize the memory manager early + initMemoryManager(); + /// @todo remove this force set of working directory later Char buffer[ _MAX_PATH ]; GetModuleFileName( NULL, buffer, sizeof( buffer ) ); @@ -787,9 +790,6 @@ Int APIENTRY WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, // Force to be loaded from a file, not a resource so same exe can be used in germany and retail. gLoadScreenBitmap = (HBITMAP)LoadImage(hInstance, "Install_Final.bmp", IMAGE_BITMAP, 0, 0, LR_SHARED|LR_LOADFROMFILE); - // initialize the memory manager early - initMemoryManager(); - CommandLine::parseCommandLineForStartup(); // register windows class and create application window