diff --git a/Generals/Code/GameEngine/Source/Common/System/Debug.cpp b/Generals/Code/GameEngine/Source/Common/System/Debug.cpp index bfe30cef5b..3cb63f0d4e 100644 --- a/Generals/Code/GameEngine/Source/Common/System/Debug.cpp +++ b/Generals/Code/GameEngine/Source/Common/System/Debug.cpp @@ -166,9 +166,6 @@ inline HWND getThreadHWND() int MessageBoxWrapper( LPCSTR lpText, LPCSTR lpCaption, UINT uType ) { HWND threadHWND = getThreadHWND(); - if (!threadHWND) - return (uType & MB_ABORTRETRYIGNORE)?IDIGNORE:IDYES; - return ::MessageBox(threadHWND, lpText, lpCaption, uType); } @@ -365,8 +362,9 @@ void DebugInit(int flags) #ifdef DEBUG_LOGGING // TheSuperHackers @info Debug initialization can happen very early. - // Therefore, parse initial commandline and initialize the client instance now. + // Determine the client instance id before creating the log file with an instance specific name. CommandLine::parseCommandLineForStartup(); + if (!rts::ClientInstance::initialize()) return; @@ -482,9 +480,11 @@ const char* DebugGetLogFileNamePrev() // ---------------------------------------------------------------------------- #ifdef DEBUG_CRASHING /** - Print a character string to the logfile and/or console, then halt execution + Print a character string to the log file and/or console, then halt execution while presenting the user with an exit/debug/ignore dialog containing the same text message. + + TheSuperHackers @tweak Now shows a message box without any logging when debug was not yet initialized. */ void DebugCrash(const char *format, ...) { @@ -493,53 +493,40 @@ void DebugCrash(const char *format, ...) // make it not static so that it'll be thread-safe. // make it big to avoid weird overflow bugs in debug mode - char theCrashBuffer[ LARGE_BUFFER ]; - if (theDebugFlags == 0) - { - if (!DX8Wrapper_IsWindowed) { - if (ApplicationHWnd) { - ShowWindow(ApplicationHWnd, SW_HIDE); - } - } - MessageBoxWrapper("DebugCrash - Debug not inited properly", "", MB_OK|MB_TASKMODAL); - } + char theCrashBuffer[ LARGE_BUFFER ]; prepBuffer(theCrashBuffer); strcat(theCrashBuffer, "ASSERTION FAILURE: "); va_list arg; va_start(arg, format); - vsprintf(theCrashBuffer + strlen(theCrashBuffer), format, arg); + vsnprintf(theCrashBuffer + strlen(theCrashBuffer), LARGE_BUFFER, format, arg); va_end(arg); - if (strlen(theCrashBuffer) >= sizeof(theCrashBuffer)) - { - if (!DX8Wrapper_IsWindowed) { - if (ApplicationHWnd) { - ShowWindow(ApplicationHWnd, SW_HIDE); - } - } - MessageBoxWrapper("String too long for debug buffers", "", MB_OK|MB_TASKMODAL); - } + whackFunnyCharacters(theCrashBuffer); -#ifdef DEBUG_LOGGING - if (ignoringAsserts()) + const bool useLogging = theDebugFlags != 0; + + if (useLogging) { - doLogOutput("**** CRASH IN FULL SCREEN - Auto-ignored, CHECK THIS LOG!"); - } - whackFunnyCharacters(theCrashBuffer); - doLogOutput(theCrashBuffer); +#ifdef DEBUG_LOGGING + if (ignoringAsserts()) + { + doLogOutput("**** CRASH IN FULL SCREEN - Auto-ignored, CHECK THIS LOG!"); + } + doLogOutput(theCrashBuffer); #endif #ifdef DEBUG_STACKTRACE - if (!(TheGlobalData && TheGlobalData->m_debugIgnoreStackTrace)) - { - doStackDump(); - } + if (!(TheGlobalData && TheGlobalData->m_debugIgnoreStackTrace)) + { + doStackDump(); + } #endif + } strcat(theCrashBuffer, "\n\nAbort->exception; Retry->debugger; Ignore->continue"); - int result = doCrashBox(theCrashBuffer, true); + const int result = doCrashBox(theCrashBuffer, useLogging); if (result == IDIGNORE && TheCurrentIgnoreCrashPtr != NULL) { diff --git a/Generals/Code/GameEngine/Source/Common/System/GameMemory.cpp b/Generals/Code/GameEngine/Source/Common/System/GameMemory.cpp index f3a8f0d514..dd4d2b9376 100644 --- a/Generals/Code/GameEngine/Source/Common/System/GameMemory.cpp +++ b/Generals/Code/GameEngine/Source/Common/System/GameMemory.cpp @@ -124,7 +124,7 @@ DECLARE_PERF_TIMER(MemoryPoolInitFilling) s_initFillerValue |= (~(s_initFillerValue << 4)) & 0xf0; s_initFillerValue |= (s_initFillerValue << 8); s_initFillerValue |= (s_initFillerValue << 16); - DEBUG_LOG(("Setting MemoryPool initFillerValue to %08x (index %d)",s_initFillerValue,index)); + //DEBUG_LOG(("Setting MemoryPool initFillerValue to %08x (index %d)",s_initFillerValue,index)); } #endif @@ -3424,6 +3424,9 @@ void initMemoryManager() TheDynamicMemoryAllocator = TheMemoryPoolFactory->createDynamicMemoryAllocator(numSubPools, pParms); // will throw on failure userMemoryManagerInitPools(); thePreMainInitFlag = false; + + DEBUG_INIT(DEBUG_FLAGS_DEFAULT); + DEBUG_LOG(("*** Initialized the Memory Manager")); } else { @@ -3433,7 +3436,7 @@ void initMemoryManager() } else { - DEBUG_CRASH(("memory manager is already inited")); + DEBUG_CRASH(("Memory Manager is already initialized")); } } @@ -3487,8 +3490,6 @@ static void preMainInitMemoryManager() { if (TheMemoryPoolFactory == NULL) { - DEBUG_INIT(DEBUG_FLAGS_DEFAULT); - DEBUG_LOG(("*** Initing Memory Manager prior to main!")); Int numSubPools; const PoolInitRec *pParms; @@ -3499,6 +3500,9 @@ static void preMainInitMemoryManager() TheDynamicMemoryAllocator = TheMemoryPoolFactory->createDynamicMemoryAllocator(numSubPools, pParms); // will throw on failure userMemoryManagerInitPools(); thePreMainInitFlag = true; + + DEBUG_INIT(DEBUG_FLAGS_DEFAULT); + DEBUG_LOG(("*** Initialized the Memory Manager prior to main!")); } } @@ -3543,6 +3547,8 @@ void shutdownMemoryManager() } theMainInitFlag = false; + + DEBUG_SHUTDOWN(); } //----------------------------------------------------------------------------- diff --git a/Generals/Code/Main/WinMain.cpp b/Generals/Code/Main/WinMain.cpp index e95670509c..55968ebb46 100644 --- a/Generals/Code/Main/WinMain.cpp +++ b/Generals/Code/Main/WinMain.cpp @@ -768,7 +768,6 @@ Int APIENTRY WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, } ::SetCurrentDirectory(buffer); - CommandLine::parseCommandLineForStartup(); #ifdef RTS_DEBUG // Turn on Memory heap tracking @@ -788,6 +787,11 @@ 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 if(!TheGlobalData->m_headless && initializeAppWindows(hInstance, nCmdShow, TheGlobalData->m_windowed) == false) return exitcode; @@ -804,9 +808,6 @@ Int APIENTRY WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, // BGC - initialize COM // OleInitialize(NULL); - // start the log - DEBUG_INIT(DEBUG_FLAGS_DEFAULT); - initMemoryManager(); // Set up version info @@ -830,7 +831,6 @@ Int APIENTRY WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, delete TheVersion; TheVersion = NULL; shutdownMemoryManager(); - DEBUG_SHUTDOWN(); return exitcode; } DEBUG_LOG(("Create Generals Mutex okay.")); @@ -849,9 +849,7 @@ Int APIENTRY WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, TheMemoryPoolFactory->memoryPoolUsageReport("AAAMemStats"); #endif - // close the log shutdownMemoryManager(); - DEBUG_SHUTDOWN(); // BGC - shut down COM // OleUninitialize(); diff --git a/GeneralsMD/Code/GameEngine/Source/Common/System/Debug.cpp b/GeneralsMD/Code/GameEngine/Source/Common/System/Debug.cpp index 508f04fc77..6bd781428d 100644 --- a/GeneralsMD/Code/GameEngine/Source/Common/System/Debug.cpp +++ b/GeneralsMD/Code/GameEngine/Source/Common/System/Debug.cpp @@ -167,9 +167,6 @@ inline HWND getThreadHWND() int MessageBoxWrapper( LPCSTR lpText, LPCSTR lpCaption, UINT uType ) { HWND threadHWND = getThreadHWND(); - if (!threadHWND) - return (uType & MB_ABORTRETRYIGNORE)?IDIGNORE:IDYES; - return ::MessageBox(threadHWND, lpText, lpCaption, uType); } @@ -366,8 +363,9 @@ void DebugInit(int flags) #ifdef DEBUG_LOGGING // TheSuperHackers @info Debug initialization can happen very early. - // Therefore, parse initial commandline and initialize the client instance now. + // Determine the client instance id before creating the log file with an instance specific name. CommandLine::parseCommandLineForStartup(); + if (!rts::ClientInstance::initialize()) return; @@ -483,9 +481,11 @@ const char* DebugGetLogFileNamePrev() // ---------------------------------------------------------------------------- #ifdef DEBUG_CRASHING /** - Print a character string to the logfile and/or console, then halt execution + Print a character string to the log file and/or console, then halt execution while presenting the user with an exit/debug/ignore dialog containing the same text message. + + TheSuperHackers @tweak Now shows a message box without any logging when debug was not yet initialized. */ void DebugCrash(const char *format, ...) { @@ -494,53 +494,40 @@ void DebugCrash(const char *format, ...) // make it not static so that it'll be thread-safe. // make it big to avoid weird overflow bugs in debug mode - char theCrashBuffer[ LARGE_BUFFER ]; - if (theDebugFlags == 0) - { - if (!DX8Wrapper_IsWindowed) { - if (ApplicationHWnd) { - ShowWindow(ApplicationHWnd, SW_HIDE); - } - } - MessageBoxWrapper("DebugCrash - Debug not inited properly", "", MB_OK|MB_TASKMODAL); - } + char theCrashBuffer[ LARGE_BUFFER ]; prepBuffer(theCrashBuffer); strcat(theCrashBuffer, "ASSERTION FAILURE: "); va_list arg; va_start(arg, format); - vsprintf(theCrashBuffer + strlen(theCrashBuffer), format, arg); + vsnprintf(theCrashBuffer + strlen(theCrashBuffer), LARGE_BUFFER, format, arg); va_end(arg); - if (strlen(theCrashBuffer) >= sizeof(theCrashBuffer)) - { - if (!DX8Wrapper_IsWindowed) { - if (ApplicationHWnd) { - ShowWindow(ApplicationHWnd, SW_HIDE); - } - } - MessageBoxWrapper("String too long for debug buffers", "", MB_OK|MB_TASKMODAL); - } + whackFunnyCharacters(theCrashBuffer); -#ifdef DEBUG_LOGGING - if (ignoringAsserts()) + const bool useLogging = theDebugFlags != 0; + + if (useLogging) { - doLogOutput("**** CRASH IN FULL SCREEN - Auto-ignored, CHECK THIS LOG!"); - } - whackFunnyCharacters(theCrashBuffer); - doLogOutput(theCrashBuffer); +#ifdef DEBUG_LOGGING + if (ignoringAsserts()) + { + doLogOutput("**** CRASH IN FULL SCREEN - Auto-ignored, CHECK THIS LOG!"); + } + doLogOutput(theCrashBuffer); #endif #ifdef DEBUG_STACKTRACE - if (!(TheGlobalData && TheGlobalData->m_debugIgnoreStackTrace)) - { - doStackDump(); - } + if (!(TheGlobalData && TheGlobalData->m_debugIgnoreStackTrace)) + { + doStackDump(); + } #endif + } strcat(theCrashBuffer, "\n\nAbort->exception; Retry->debugger; Ignore->continue"); - int result = doCrashBox(theCrashBuffer, true); + const int result = doCrashBox(theCrashBuffer, useLogging); if (result == IDIGNORE && TheCurrentIgnoreCrashPtr != NULL) { diff --git a/GeneralsMD/Code/GameEngine/Source/Common/System/GameMemory.cpp b/GeneralsMD/Code/GameEngine/Source/Common/System/GameMemory.cpp index 53f3dbb1f7..a48ec74b38 100644 --- a/GeneralsMD/Code/GameEngine/Source/Common/System/GameMemory.cpp +++ b/GeneralsMD/Code/GameEngine/Source/Common/System/GameMemory.cpp @@ -126,7 +126,7 @@ DECLARE_PERF_TIMER(MemoryPoolInitFilling) s_initFillerValue |= (~(s_initFillerValue << 4)) & 0xf0; s_initFillerValue |= (s_initFillerValue << 8); s_initFillerValue |= (s_initFillerValue << 16); - DEBUG_LOG(("Setting MemoryPool initFillerValue to %08x (index %d)",s_initFillerValue,index)); + //DEBUG_LOG(("Setting MemoryPool initFillerValue to %08x (index %d)",s_initFillerValue,index)); } #endif @@ -3414,6 +3414,9 @@ void initMemoryManager() TheDynamicMemoryAllocator = TheMemoryPoolFactory->createDynamicMemoryAllocator(numSubPools, pParms); // will throw on failure userMemoryManagerInitPools(); thePreMainInitFlag = false; + + DEBUG_INIT(DEBUG_FLAGS_DEFAULT); + DEBUG_LOG(("*** Initialized the Memory Manager")); } else { @@ -3423,7 +3426,7 @@ void initMemoryManager() } else { - DEBUG_CRASH(("memory manager is already inited")); + DEBUG_CRASH(("Memory Manager is already initialized")); } } @@ -3477,8 +3480,6 @@ static void preMainInitMemoryManager() { if (TheMemoryPoolFactory == NULL) { - DEBUG_INIT(DEBUG_FLAGS_DEFAULT); - DEBUG_LOG(("*** Initing Memory Manager prior to main!")); Int numSubPools; const PoolInitRec *pParms; @@ -3489,6 +3490,9 @@ static void preMainInitMemoryManager() TheDynamicMemoryAllocator = TheMemoryPoolFactory->createDynamicMemoryAllocator(numSubPools, pParms); // will throw on failure userMemoryManagerInitPools(); thePreMainInitFlag = true; + + DEBUG_INIT(DEBUG_FLAGS_DEFAULT); + DEBUG_LOG(("*** Initialized the Memory Manager prior to main!")); } } @@ -3533,6 +3537,8 @@ void shutdownMemoryManager() } theMainInitFlag = false; + + DEBUG_SHUTDOWN(); } //----------------------------------------------------------------------------- diff --git a/GeneralsMD/Code/Main/WinMain.cpp b/GeneralsMD/Code/Main/WinMain.cpp index 631b00d3ea..6f7d9d663e 100644 --- a/GeneralsMD/Code/Main/WinMain.cpp +++ b/GeneralsMD/Code/Main/WinMain.cpp @@ -794,7 +794,6 @@ Int APIENTRY WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, } ::SetCurrentDirectory(buffer); - CommandLine::parseCommandLineForStartup(); #ifdef RTS_DEBUG // Turn on Memory heap tracking @@ -834,6 +833,11 @@ 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 if(!TheGlobalData->m_headless && initializeAppWindows(hInstance, nCmdShow, TheGlobalData->m_windowed) == false) return exitcode; @@ -850,9 +854,6 @@ Int APIENTRY WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, // BGC - initialize COM // OleInitialize(NULL); - // start the log - DEBUG_INIT(DEBUG_FLAGS_DEFAULT); - initMemoryManager(); // Set up version info @@ -876,7 +877,6 @@ Int APIENTRY WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, delete TheVersion; TheVersion = NULL; shutdownMemoryManager(); - DEBUG_SHUTDOWN(); return exitcode; } DEBUG_LOG(("Create Generals Mutex okay.")); @@ -896,9 +896,7 @@ Int APIENTRY WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, TheMemoryPoolFactory->memoryPoolUsageReport("AAAMemStats"); #endif - // close the log shutdownMemoryManager(); - DEBUG_SHUTDOWN(); // BGC - shut down COM // OleUninitialize();