diff --git a/CMakeLists.txt b/CMakeLists.txt index 59c2aeb4..cc985830 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -68,6 +68,7 @@ option(USE_LTO "Use link-time optimization" OFF) option(WITH_BETTER_RENDERER "Experimental multi-backend renderer based on NVRHI" ON) option(GENERATE_PDB "Generate executable with program debugging symbols" ON) option(ENABLE_MCC "Enable multicore compilation" ON) +option(WITHDUMPGEN "Enable generating DMP files on crash" ON) set(BUILD_EXAMPLES OFF CACHE BOOL "" FORCE) @@ -265,6 +266,10 @@ if (WITH_LUA) set(SOURCES ${SOURCES} "lua.cpp") endif() +if (WITHDUMPGEN) + set(DEFINITIONS ${DEFINITIONS} "WITHDUMPGEN") +endif() + if (WITH_OPENGL_MODERN) set(SOURCES ${SOURCES} "opengl33geometrybank.cpp" diff --git a/EU07.cpp b/EU07.cpp index 2d7a66fd..5ac2fbc5 100644 --- a/EU07.cpp +++ b/EU07.cpp @@ -21,6 +21,10 @@ Stele, firleju, szociu, hunter, ZiomalCl, OLI_EU and others #include "application.h" #include "Logs.h" #include +#ifdef WITHDUMPGEN +#include +#include +#endif #ifdef _MSC_VER #pragma comment(linker, "/subsystem:windows /ENTRY:mainCRTStartup") @@ -28,8 +32,32 @@ Stele, firleju, szociu, hunter, ZiomalCl, OLI_EU and others void export_e3d_standalone(std::string in, std::string out, int flags, bool dynamic); +#ifdef WITHDUMPGEN +LONG WINAPI CrashHandler(EXCEPTION_POINTERS *ExceptionInfo) +{ + HANDLE hFile = CreateFileA("crash.dmp", GENERIC_WRITE, 0, nullptr, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr); + if (hFile != INVALID_HANDLE_VALUE) + { + MINIDUMP_EXCEPTION_INFORMATION dumpInfo; + dumpInfo.ThreadId = GetCurrentThreadId(); + dumpInfo.ExceptionPointers = ExceptionInfo; + dumpInfo.ClientPointers = FALSE; + + MiniDumpWriteDump(GetCurrentProcess(), GetCurrentProcessId(), hFile, MiniDumpWithDataSegs, &dumpInfo, nullptr, nullptr); + CloseHandle(hFile); + } + + return EXCEPTION_EXECUTE_HANDLER; +} +#endif + + int main(int argc, char *argv[]) { +#ifdef WITHDUMPGEN + SetUnhandledExceptionFilter(CrashHandler); +#endif + // quick short-circuit for standalone e3d export if (argc == 6 && std::string(argv[1]) == "-e3d") { std::string in(argv[2]);