win: add minidumps to fatal errors

This commit is contained in:
Kae 2024-10-18 14:18:40 +11:00
parent 0a5e92ef38
commit aac3e53941
2 changed files with 30 additions and 4 deletions

View File

@ -41,6 +41,7 @@
// Change planet name to support the new internal string formatting.
"planetNameFormatString" : "- {} -",
"planetTextOffset" : [0, 120],
"planetTextStyle" : {
"backDirectives" : "border=5;fff;fff?border=1;fff;fff7?multiply=000",
"fontSize" : 24

View File

@ -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;
}