Skip to content

Commit bc3b27c

Browse files
committed
Replicate in Generals
1 parent 4247d47 commit bc3b27c

File tree

3 files changed

+38
-47
lines changed

3 files changed

+38
-47
lines changed

Generals/Code/GameEngine/Source/Common/System/Debug.cpp

Lines changed: 23 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -166,9 +166,6 @@ inline HWND getThreadHWND()
166166
int MessageBoxWrapper( LPCSTR lpText, LPCSTR lpCaption, UINT uType )
167167
{
168168
HWND threadHWND = getThreadHWND();
169-
if (!threadHWND)
170-
return (uType & MB_ABORTRETRYIGNORE)?IDIGNORE:IDYES;
171-
172169
return ::MessageBox(threadHWND, lpText, lpCaption, uType);
173170
}
174171

@@ -365,8 +362,9 @@ void DebugInit(int flags)
365362
#ifdef DEBUG_LOGGING
366363

367364
// TheSuperHackers @info Debug initialization can happen very early.
368-
// Therefore, parse initial commandline and initialize the client instance now.
365+
// Determine the client instance id before creating the log file with an instance specific name.
369366
CommandLine::parseCommandLineForStartup();
367+
370368
if (!rts::ClientInstance::initialize())
371369
return;
372370

@@ -482,9 +480,11 @@ const char* DebugGetLogFileNamePrev()
482480
// ----------------------------------------------------------------------------
483481
#ifdef DEBUG_CRASHING
484482
/**
485-
Print a character string to the logfile and/or console, then halt execution
483+
Print a character string to the log file and/or console, then halt execution
486484
while presenting the user with an exit/debug/ignore dialog containing the same
487485
text message.
486+
487+
TheSuperHackers @tweak Now shows a message box without any logging when debug was not yet initialized.
488488
*/
489489
void DebugCrash(const char *format, ...)
490490
{
@@ -493,53 +493,40 @@ void DebugCrash(const char *format, ...)
493493

494494
// make it not static so that it'll be thread-safe.
495495
// make it big to avoid weird overflow bugs in debug mode
496-
char theCrashBuffer[ LARGE_BUFFER ];
497-
if (theDebugFlags == 0)
498-
{
499-
if (!DX8Wrapper_IsWindowed) {
500-
if (ApplicationHWnd) {
501-
ShowWindow(ApplicationHWnd, SW_HIDE);
502-
}
503-
}
504-
MessageBoxWrapper("DebugCrash - Debug not inited properly", "", MB_OK|MB_TASKMODAL);
505-
}
496+
char theCrashBuffer[ LARGE_BUFFER ];
506497

507498
prepBuffer(theCrashBuffer);
508499
strcat(theCrashBuffer, "ASSERTION FAILURE: ");
509500

510501
va_list arg;
511502
va_start(arg, format);
512-
vsprintf(theCrashBuffer + strlen(theCrashBuffer), format, arg);
503+
vsnprintf(theCrashBuffer + strlen(theCrashBuffer), LARGE_BUFFER, format, arg);
513504
va_end(arg);
514505

515-
if (strlen(theCrashBuffer) >= sizeof(theCrashBuffer))
516-
{
517-
if (!DX8Wrapper_IsWindowed) {
518-
if (ApplicationHWnd) {
519-
ShowWindow(ApplicationHWnd, SW_HIDE);
520-
}
521-
}
522-
MessageBoxWrapper("String too long for debug buffers", "", MB_OK|MB_TASKMODAL);
523-
}
506+
whackFunnyCharacters(theCrashBuffer);
524507

525-
#ifdef DEBUG_LOGGING
526-
if (ignoringAsserts())
508+
const bool useLogging = theDebugFlags != 0;
509+
510+
if (useLogging)
527511
{
528-
doLogOutput("**** CRASH IN FULL SCREEN - Auto-ignored, CHECK THIS LOG!");
529-
}
530-
whackFunnyCharacters(theCrashBuffer);
531-
doLogOutput(theCrashBuffer);
512+
#ifdef DEBUG_LOGGING
513+
if (ignoringAsserts())
514+
{
515+
doLogOutput("**** CRASH IN FULL SCREEN - Auto-ignored, CHECK THIS LOG!");
516+
}
517+
doLogOutput(theCrashBuffer);
532518
#endif
533519
#ifdef DEBUG_STACKTRACE
534-
if (!(TheGlobalData && TheGlobalData->m_debugIgnoreStackTrace))
535-
{
536-
doStackDump();
537-
}
520+
if (!(TheGlobalData && TheGlobalData->m_debugIgnoreStackTrace))
521+
{
522+
doStackDump();
523+
}
538524
#endif
525+
}
539526

540527
strcat(theCrashBuffer, "\n\nAbort->exception; Retry->debugger; Ignore->continue");
541528

542-
int result = doCrashBox(theCrashBuffer, true);
529+
const int result = doCrashBox(theCrashBuffer, useLogging);
543530

544531
if (result == IDIGNORE && TheCurrentIgnoreCrashPtr != NULL)
545532
{

Generals/Code/GameEngine/Source/Common/System/GameMemory.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ DECLARE_PERF_TIMER(MemoryPoolInitFilling)
124124
s_initFillerValue |= (~(s_initFillerValue << 4)) & 0xf0;
125125
s_initFillerValue |= (s_initFillerValue << 8);
126126
s_initFillerValue |= (s_initFillerValue << 16);
127-
DEBUG_LOG(("Setting MemoryPool initFillerValue to %08x (index %d)",s_initFillerValue,index));
127+
//DEBUG_LOG(("Setting MemoryPool initFillerValue to %08x (index %d)",s_initFillerValue,index));
128128
}
129129
#endif
130130

@@ -3424,6 +3424,9 @@ void initMemoryManager()
34243424
TheDynamicMemoryAllocator = TheMemoryPoolFactory->createDynamicMemoryAllocator(numSubPools, pParms); // will throw on failure
34253425
userMemoryManagerInitPools();
34263426
thePreMainInitFlag = false;
3427+
3428+
DEBUG_INIT(DEBUG_FLAGS_DEFAULT);
3429+
DEBUG_LOG(("*** Initialized the Memory Manager"));
34273430
}
34283431
else
34293432
{
@@ -3433,7 +3436,7 @@ void initMemoryManager()
34333436
}
34343437
else
34353438
{
3436-
DEBUG_CRASH(("memory manager is already inited"));
3439+
DEBUG_CRASH(("Memory Manager is already initialized"));
34373440
}
34383441
}
34393442

@@ -3487,8 +3490,6 @@ static void preMainInitMemoryManager()
34873490
{
34883491
if (TheMemoryPoolFactory == NULL)
34893492
{
3490-
DEBUG_INIT(DEBUG_FLAGS_DEFAULT);
3491-
DEBUG_LOG(("*** Initing Memory Manager prior to main!"));
34923493

34933494
Int numSubPools;
34943495
const PoolInitRec *pParms;
@@ -3499,6 +3500,9 @@ static void preMainInitMemoryManager()
34993500
TheDynamicMemoryAllocator = TheMemoryPoolFactory->createDynamicMemoryAllocator(numSubPools, pParms); // will throw on failure
35003501
userMemoryManagerInitPools();
35013502
thePreMainInitFlag = true;
3503+
3504+
DEBUG_INIT(DEBUG_FLAGS_DEFAULT);
3505+
DEBUG_LOG(("*** Intialized the Memory Manager prior to main!"));
35023506
}
35033507
}
35043508

@@ -3543,6 +3547,8 @@ void shutdownMemoryManager()
35433547
}
35443548

35453549
theMainInitFlag = false;
3550+
3551+
DEBUG_SHUTDOWN();
35463552
}
35473553

35483554
//-----------------------------------------------------------------------------

Generals/Code/Main/WinMain.cpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -768,7 +768,6 @@ Int APIENTRY WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
768768
}
769769
::SetCurrentDirectory(buffer);
770770

771-
CommandLine::parseCommandLineForStartup();
772771

773772
#ifdef RTS_DEBUG
774773
// Turn on Memory heap tracking
@@ -788,6 +787,11 @@ Int APIENTRY WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
788787
// Force to be loaded from a file, not a resource so same exe can be used in germany and retail.
789788
gLoadScreenBitmap = (HBITMAP)LoadImage(hInstance, "Install_Final.bmp", IMAGE_BITMAP, 0, 0, LR_SHARED|LR_LOADFROMFILE);
790789

790+
// initialize the memory manager early
791+
initMemoryManager();
792+
793+
CommandLine::parseCommandLineForStartup();
794+
791795
// register windows class and create application window
792796
if(!TheGlobalData->m_headless && initializeAppWindows(hInstance, nCmdShow, TheGlobalData->m_windowed) == false)
793797
return exitcode;
@@ -804,9 +808,6 @@ Int APIENTRY WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
804808
// BGC - initialize COM
805809
// OleInitialize(NULL);
806810

807-
// start the log
808-
DEBUG_INIT(DEBUG_FLAGS_DEFAULT);
809-
initMemoryManager();
810811

811812

812813
// Set up version info
@@ -830,7 +831,6 @@ Int APIENTRY WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
830831
delete TheVersion;
831832
TheVersion = NULL;
832833
shutdownMemoryManager();
833-
DEBUG_SHUTDOWN();
834834
return exitcode;
835835
}
836836
DEBUG_LOG(("Create Generals Mutex okay."));
@@ -849,9 +849,7 @@ Int APIENTRY WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
849849
TheMemoryPoolFactory->memoryPoolUsageReport("AAAMemStats");
850850
#endif
851851

852-
// close the log
853852
shutdownMemoryManager();
854-
DEBUG_SHUTDOWN();
855853

856854
// BGC - shut down COM
857855
// OleUninitialize();

0 commit comments

Comments
 (0)