Skip to content

Commit aeb788f

Browse files
committed
Crash dump improvements
- Added additional error checking in case minidump generation fails. Should hopefully report when minidumps fail to create and log the last windows error. Can't say for certain since I don't know how to repro it - Removed some info from the minidump that I'm not using at this time. Makes minidumps much smaller. ~15MB in my tests instead of several hundred MB
1 parent 3e02788 commit aeb788f

File tree

1 file changed

+28
-9
lines changed

1 file changed

+28
-9
lines changed

Nanoforge/CrashHandler.cpp

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,26 @@ int GenerateMinidump(EXCEPTION_POINTERS* pExceptionPointers)
3131
ExpParam.ExceptionPointers = pExceptionPointers;
3232
ExpParam.ClientPointers = TRUE;
3333

34-
MINIDUMP_TYPE dumpType = (MINIDUMP_TYPE)(MiniDumpWithPrivateReadWriteMemory | MiniDumpIgnoreInaccessibleMemory |
35-
MiniDumpWithDataSegs | MiniDumpWithHandleData | MiniDumpWithFullMemoryInfo |
36-
MiniDumpWithThreadInfo | MiniDumpWithUnloadedModules);
34+
MINIDUMP_TYPE dumpType = (MINIDUMP_TYPE)(MiniDumpNormal | MiniDumpWithIndirectlyReferencedMemory | MiniDumpWithDataSegs | MiniDumpFilterModulePaths);
3735

38-
//Write dmp file
36+
//Create .dmp file
3937
hDumpFile = CreateFile(outPath.c_str(), GENERIC_READ | GENERIC_WRITE, FILE_SHARE_WRITE | FILE_SHARE_READ, 0, CREATE_ALWAYS, 0, 0);
40-
bool success = MiniDumpWriteDump(GetCurrentProcess(), GetCurrentProcessId(), hDumpFile, dumpType, &ExpParam, NULL, NULL);
41-
return EXCEPTION_EXECUTE_HANDLER;
38+
if (!hDumpFile)
39+
{
40+
int lastError = GetLastError();
41+
LOG_ERROR("Failed to create minidump file. LastError: {}", lastError);
42+
return lastError;
43+
}
44+
45+
//Write .dmp file
46+
if (MiniDumpWriteDump(GetCurrentProcess(), GetCurrentProcessId(), hDumpFile, dumpType, &ExpParam, NULL, NULL) != TRUE)
47+
{
48+
int lastError = GetLastError();
49+
LOG_ERROR("Failed to write minidump file. LastError: {}", lastError);
50+
return lastError;
51+
}
52+
53+
return 0;
4254
}
4355

4456
//Override windows crash handler to catch unhandled SEH exceptions
@@ -48,11 +60,18 @@ LONG WINAPI CrashHandler(EXCEPTION_POINTERS* exceptions)
4860
PEXCEPTION_RECORD& record = exceptions->ExceptionRecord;
4961
bool continuable = record->ExceptionFlags == 0;
5062
string errorCodeString = ExceptionCodeToString(record->ExceptionCode);
51-
string errorMessage = fmt::format("A fatal error has occurred! Nanoforge will crash once you press \"OK\". Please wait for the window to close so the crash dump can save. After that send MasterLog.log and the most recent CrashDump file to moneyl on the RF discord. If you're not on the RF discord you can join it by making a discord account and going to RFChat.com. Exception code: {}. Continuable: {}", errorCodeString, continuable);
63+
string errorMessage = fmt::format("A fatal error has occurred! Nanoforge will crash once you press \"OK\". Please wait for the window to close so the crash dump can save. After that send MasterLog.log and the most recent .dmp file to moneyl on the RF discord. If you're not on the RF discord you can join it by making a discord account and going to RFChat.com. Exception code: {}", errorCodeString);
5264

5365
//Log crash data, generate minidump, and notify user via message box
54-
GenerateMinidump(exceptions);
55-
ShowMessageBox(errorMessage, "Unhandled exception encountered!", MB_OK);
66+
int minidumpResult = GenerateMinidump(exceptions);
67+
if (minidumpResult == 0)
68+
{
69+
ShowMessageBox(errorMessage, "Unhandled exception encountered!", MB_OK);
70+
}
71+
else
72+
{
73+
ShowMessageBox("Failed to create minidump after fatal error! Please send MasterLog.log to moneyl on the RF discord (RFChat.com). Nanoforge will exit after you click OK.", "Failed to create minidump.", MB_OK);
74+
}
5675
LOG_ERROR(errorMessage);
5776
return EXCEPTION_CONTINUE_SEARCH; //Crash regardless of continuability. In testing I found it'd endlessly call the crash handler when continuing after some continuable exceptions
5877
}

0 commit comments

Comments
 (0)