Add auto dmp file genration

This commit is contained in:
2025-06-02 22:41:39 +02:00
parent 25bc32e84f
commit ac2c5ab4cf
2 changed files with 33 additions and 0 deletions

View File

@@ -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"

View File

@@ -21,6 +21,10 @@ Stele, firleju, szociu, hunter, ZiomalCl, OLI_EU and others
#include "application.h"
#include "Logs.h"
#include <cstdlib>
#ifdef WITHDUMPGEN
#include <Windows.h>
#include <DbgHelp.h>
#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]);