diff options
author | Kae <80987908+Novaenia@users.noreply.github.com> | 2024-10-18 14:18:40 +1100 |
---|---|---|
committer | Kae <80987908+Novaenia@users.noreply.github.com> | 2024-10-18 14:18:40 +1100 |
commit | aac3e5394157a0b55a6512cb2b94b20a57c1b98e (patch) | |
tree | a04fa8d6cd61edf6f586b135f991932611dde84b /source/core/StarSignalHandler_windows.cpp | |
parent | 0a5e92ef389a67956b1075cf7e4f0c3b2461c190 (diff) |
win: add minidumps to fatal errors
Diffstat (limited to 'source/core/StarSignalHandler_windows.cpp')
-rw-r--r-- | source/core/StarSignalHandler_windows.cpp | 33 |
1 files changed, 29 insertions, 4 deletions
diff --git a/source/core/StarSignalHandler_windows.cpp b/source/core/StarSignalHandler_windows.cpp index 29e93c5..13a36ac 100644 --- a/source/core/StarSignalHandler_windows.cpp +++ b/source/core/StarSignalHandler_windows.cpp @@ -4,11 +4,35 @@ #include "StarLogging.hpp" #include <windows.h> +#include "minidumpapiset.h" namespace Star { String g_sehMessage; +static DWORD WINAPI writeMiniDump(void* ExceptionInfo) { + auto hFile = CreateFileA("starbound.dmp", GENERIC_WRITE, FILE_SHARE_READ, 0, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0); + if (hFile == INVALID_HANDLE_VALUE) + return 0; + MINIDUMP_EXCEPTION_INFORMATION dumpExceptionInfo{}; + dumpExceptionInfo.ThreadId = GetCurrentThreadId(); + dumpExceptionInfo.ExceptionPointers = (PEXCEPTION_POINTERS)ExceptionInfo; + dumpExceptionInfo.ClientPointers = FALSE; + MiniDumpWriteDump( + GetCurrentProcess(), + GetCurrentProcessId(), + hFile, + MiniDumpNormal, + &dumpExceptionInfo, + NULL, + NULL); + CloseHandle(hFile); + if (dumpExceptionInfo.ExceptionPointers->ExceptionRecord->ExceptionCode == EXCEPTION_STACK_OVERFLOW) { + MessageBoxA(NULL, "Stack overflow encountered\nA minidump has been generated", NULL, MB_OK | MB_ICONERROR | MB_SETFOREGROUND); + } + return 0; +}; + struct SignalHandlerImpl { bool handlingFatal; bool handlingInterrupt; @@ -98,9 +122,7 @@ struct SignalHandlerImpl { } static LONG CALLBACK vectoredExceptionHandler(PEXCEPTION_POINTERS ExceptionInfo) { - if (ExceptionInfo->ExceptionRecord->ExceptionCode == EXCEPTION_STACK_OVERFLOW) { - fatalError("Stack overflow encountered", false); - } + auto thread = CreateThread(NULL, 0, writeMiniDump, (void*)ExceptionInfo, 0, NULL); if (ExceptionInfo->ExceptionRecord->ExceptionCode == EXCEPTION_ACCESS_VIOLATION) { handleFatalError("Access violation detected", ExceptionInfo); return EXCEPTION_CONTINUE_EXECUTION; @@ -143,7 +165,10 @@ struct SignalHandlerImpl { handleFatalError("Error occured", ExceptionInfo); return EXCEPTION_CONTINUE_EXECUTION; } - + if (thread != NULL) { + WaitForSingleObject(thread, 10000); + CloseHandle(thread); + } return EXCEPTION_CONTINUE_SEARCH; } |