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
build(cmake): make a Release crash leave evidence behind
Olcay Seygan315c25b836e6
diff --git a/GeneralsMD/Code/CMakeLists.txt b/GeneralsMD/Code/CMakeLists.txtindex caa2cb22b..44a73c45b 100644--- a/GeneralsMD/Code/CMakeLists.txt+++ b/GeneralsMD/Code/CMakeLists.txt@@ -10,10 +10,27 @@ set(WW ${CMAKE_CURRENT_SOURCE_DIR}/Libraries/Source/WWVegas)set(COMP ${CMAKE_CURRENT_SOURCE_DIR}/Libraries/Source/Compression)add_compile_definitions(WIN32 _WINDOWS _CRT_SECURE_NO_WARNINGS _CRT_NONSTDC_NO_WARNINGS)++# EA's own switch for exactly this situation ("Good for startup problems", Debug.h):+# it turns DEBUG_LOG back on in a Release build so the hundreds of existing log+# calls in GameEngine::init land in Run/generals.exe-<machine>.log. Without it a+# quiet failure in init leaves nothing behind at all - GameEngine::init's+# catch (ErrorCode) swallows everything that is not ERROR_INVALID_D3D, and WinMain's+# outer catch (...) swallows the rest, so the exe just returns 0. Applied per target+# at the bottom of this file, not globally: WWVegas' wwdebug.h includes GameEngine's+# Debug.h and routes WWDEBUG_SAY into DEBUG_LOG, so a global define makes wwmath and+# friends call DebugLog(), which only exists in gameengine - every leaf test exe then+# fails to link. The WW libraries' own chatter is not what we are after anyway.+option(RELEASE_DEBUG_LOGGING "Write the startup debug log in Release builds" ON)if(MSVC)# /permissive- is off on purpose: this is 2003-era code and templates here rely on# pre-two-phase-lookup name binding (simplevec.h et al).- add_compile_options(/W3 /permissive /EHsc)+ # /EHa, not /EHsc: WinMain installs _set_se_translator(DumpExceptionInfo) to turn an+ # access violation into a C++ exception and write ReleaseCrashInfo.txt on the way. A+ # translator only runs in code compiled with asynchronous EH, so under /EHsc the hook+ # is dead (MSVC says so: "warning C4535: _set_se_translator() requires /EHa") and a+ # faulting frame just kills the process with 0xC0000005 and no log at all.+ add_compile_options(/W3 /permissive /EHa)# There is no debugger on the porting machine, so ReleaseCrashInfo.txt's stack# dump is the only stack we get. StackDump.cpp walks the EBP chain by hand and# /O2 implies /Oy (no frame pointer), which leaves that dump empty; /Zi + /DEBUG@@ -396,6 +413,9 @@ file(WRITE ${GENERATED}/GeneratedVersion.hadd_executable(generals WIN32 ${CMAKE_CURRENT_SOURCE_DIR}/Main/WinMain.cpp${CMAKE_CURRENT_SOURCE_DIR}/Main/RTS.RC)target_include_directories(generals PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/Main ${GENERATED})+# A .map turns the "fault offset" in the Windows Application Error event into a+# function name without a debugger: find the last entry whose RVA is <= the offset.+target_link_options(generals PRIVATE /MAP)set_target_properties(generals PROPERTIES CXX_STANDARD 17)target_link_libraries(generals PRIVATE gameenginedevicewinmm dsound wsock32 ole32 oleaut32 uuid)@@ -470,3 +490,9 @@ set_target_properties(test_gameengine PROPERTIES CXX_STANDARD 17)add_test(NAME wwmath_selfcheck COMMAND wwmath_selfcheck)add_test(NAME compression_selfcheck COMMAND compression_selfcheck)add_test(NAME dx8_smoke COMMAND dx8_smoke)++if(RELEASE_DEBUG_LOGGING)+ target_compile_definitions(gameengine PRIVATE RELEASE_DEBUG_LOGGING)+ target_compile_definitions(gameenginedevice PRIVATE RELEASE_DEBUG_LOGGING)+ target_compile_definitions(generals PRIVATE RELEASE_DEBUG_LOGGING)+endif()diff --git a/GeneralsMD/Code/Main/WinMain.cpp b/GeneralsMD/Code/Main/WinMain.cppindex c07319742..0f65a3d19 100644--- a/GeneralsMD/Code/Main/WinMain.cpp+++ b/GeneralsMD/Code/Main/WinMain.cpp@@ -868,6 +868,17 @@ char *nextParam(char *newSource, char *seps)// Necessary to allow memory managers and such to have useful critical sectionsstatic CriticalSection critSec1, critSec2, critSec3, critSec4, critSec5;+// _set_se_translator below only covers the thread that installs it, so a fault on one+// 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.+static LONG WINAPI dumpUnhandledException( EXCEPTION_POINTERS *e_info )+{+ DEBUG_LOG(("Unhandled exception on thread %d\n", GetCurrentThreadId()));+ DumpExceptionInfo( e_info->ExceptionRecord->ExceptionCode, e_info );+ return EXCEPTION_EXECUTE_HANDLER;+}+// WinMain ====================================================================/** Application entry point *///=============================================================================@@ -883,6 +894,7 @@ Int APIENTRY WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,try {_set_se_translator( DumpExceptionInfo ); // Hook that allows stack trace.+ SetUnhandledExceptionFilter( dumpUnhandledException ); // ...on every other thread too.//// there is something about checkin in and out the .dsp and .dsw files// that blows the working directory information away on each of thediff --git a/GeneralsMD/Code/Tests/test_gameengine_stubs.cpp b/GeneralsMD/Code/Tests/test_gameengine_stubs.cppindex dff58520f..5ef9ce9b2 100644--- a/GeneralsMD/Code/Tests/test_gameengine_stubs.cpp+++ b/GeneralsMD/Code/Tests/test_gameengine_stubs.cpp@@ -71,6 +71,9 @@ AsciiString MapObject::getWaypointName( void )//////////////////////////////////////////////////////////////////////////////HWND ApplicationHWnd = NULL;++/* Debug.cpp names its log file after this; WinMain.cpp owns it in the real exe. */+char *gAppPrefix = "test_";ProjectedShadowManager *TheProjectedShadowManager = NULL;const Char *g_strFile = "data\\Generals.str";