Zero Hour rebuilt from EA's source: x64, Direct3D 11, VS2022/CMake, ~60 original bugs fixed, an AI that builds a base. Bring your own game.
C++ cmakecnccommand-and-conquercppdirectx11game-enginegame-preservationgeneralsrtssage-enginex64zero-hour
fix(main): write a crash report for worker faults and escaped exceptions
Olcay Seygan61f72b39b846
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 2c2098417..f11981e63 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -766,7 +766,12 @@ found and fixed — EA's own, not port damage.**- A log that could not be rotated says so, in the log. Rotation fails when a second copy of the gamehas the file open, and the ".prev" file next to it then holds some older run than the one before -which is a bug report read wrong.-- Something going wrong now writes a readable crash report.+- Something going wrong now writes a readable crash report. That includes the two cases that used to+ write none: a fault in the work the game does in the background, such as moving the cursor, and an+ error during loading that closed the game as if you had quit. The second one then set off the first+ on its way out, so the one report a player could send described the wrong crash. When the game the+ launcher started still closes on an error with no report, the launcher sends the exit code and the+ log on its own.## Units take corners wide, and drive round a jam instead of into itdiff --git a/GeneralsMD/Code/GameEngine/Source/Common/System/Debug.cpp b/GeneralsMD/Code/GameEngine/Source/Common/System/Debug.cppindex 4feced6b7..ab7d2aceb 100644--- a/GeneralsMD/Code/GameEngine/Source/Common/System/Debug.cpp+++ b/GeneralsMD/Code/GameEngine/Source/Common/System/Debug.cpp@@ -741,6 +741,8 @@ void ReleaseCrash(const char *reason)if (hadPreviousCrashLog && rotated != 0)fprintf(theReleaseCrashLogFile, "(the previous crash report could not be rotated aside; %s is older than it looks)\n", prevbuf);fprintf(theReleaseCrashLogFile, "\nLast error:\n%s\n\nCurrent stack:\n", g_LastErrorDump.str());+ // The stack walk below can fault, and the reason and the registers above it must survive that.+ fflush(theReleaseCrashLogFile);const int STACKTRACE_SIZE = 12;// 1, not 6: FillStackAddresses drops its own frame itself now, so 6 skipped// past everything the game did and logged two ntdll frames instead.diff --git a/GeneralsMD/Code/Main/WinMain.cpp b/GeneralsMD/Code/Main/WinMain.cppindex 70a32f85e..5e567b078 100644--- a/GeneralsMD/Code/Main/WinMain.cpp+++ b/GeneralsMD/Code/Main/WinMain.cpp@@ -51,7 +51,9 @@#include "Common/Debug.h"#include "Common/EarlyCommandLine.h"#include "Common/EarlyOptions.h"+#include "Common/Errors.h"#include "Common/GameMemory.h"+#include "Common/INIException.h"#include "Common/SafeDisc/CdaPfn.h"#include "Common/StackDump.h"#include "Common/MessageStream.h"@@ -986,10 +988,23 @@ static CriticalSection critSec1, critSec2, critSec3, critSec4, critSec5;// of the engine's worker threads (WW3D's texture loader, the GameSpy threads) took the// process down with nothing in the log at all. The unhandled-exception filter is// process-wide and is handed the same EXCEPTION_POINTERS, so it feeds the same dump.+//+// The dump only ever went to the log, and ReleaseCrashInfo.txt is the file the launcher sends, so a+// worker thread's fault reached nobody unless the player saved the report by hand. ReleaseCrash+// writes that file and ends the process. The dump's stack walk is guarded because it has already+// faulted inside this filter on a player's machine; the registers are in g_LastErrorDump before it.static LONG WINAPI dumpUnhandledException( EXCEPTION_POINTERS *e_info ){DEBUG_LOG(("Unhandled exception on thread %d\n", GetCurrentThreadId()));- DumpExceptionInfo( e_info->ExceptionRecord->ExceptionCode, e_info );+ __try+ {+ DumpExceptionInfo( e_info->ExceptionRecord->ExceptionCode, e_info );+ }+ __except( EXCEPTION_EXECUTE_HANDLER )+ {+ DEBUG_LOG(("The exception dump faulted part way through\n"));+ }+ ReleaseCrash( "Uncaught exception on a worker thread" );return EXCEPTION_EXECUTE_HANDLER;}@@ -1271,10 +1286,25 @@ Int APIENTRY WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,// BGC - shut down COM// OleUninitialize();- }- catch (...)- {-+ }+ /* Whatever escaped the engine used to end in an empty catch here, and WinMain returned as if the+ player had quit. The CRT then ran the static destructors while WW3D's threads were still+ running: the thread list was destroyed first, and the mouse or texture loader thread faulted+ taking itself off it (Except.cpp, Unregister_Thread_ID), which is all a player's report ever+ showed. Name what was thrown, and leave through ReleaseCrash's _exit so no destructor runs. */+ catch (INIException e)+ {+ RELEASE_CRASH((e.mFailureMessage ? e.mFailureMessage : "Uncaught INI exception in WinMain"));+ }+ catch (ErrorCode ec)+ {+ char why[ 64 ];+ snprintf( why, sizeof(why), "Uncaught ErrorCode 0x%08x in WinMain", (UnsignedInt)ec );+ RELEASE_CRASH((why));+ }+ catch (...)+ {+ RELEASE_CRASH(("Uncaught exception in WinMain"));}TheUnicodeStringCriticalSection = NULL;