Skip to content

Add crash handler: write crashlog + minidump to the game folder - #11

Open
tais wants to merge 1 commit into
masterfrom
add-crash-handler
Open

tais wants to merge 1 commit into
masterfrom
add-crash-handler

Conversation

@tais

@tais tais commented Jul 8, 2026

Copy link
Copy Markdown
Owner

Problem

The shipped build has no crash reporting. The __try/__except around the game (sgp.cpp) is behind ENABLE_EXCEPTION_HANDLING, which is never defined, so an unhandled exception just terminates the process with nothing written — player crash reports are unactionable.

What this adds

A top-level crash handler, installed as the very first thing in WinMain. On any crash it writes two files to the game folder:

  • CrashLog_<pid>.txt — readable summary: build version, timestamp, exception type, faulting module + offset, read/write access-violation address, and a symbolic call stack (function + file:line when a .pdb is beside the exe, module+offset otherwise). Actionable without a debugger.
  • CrashDump_<pid>.dmp — a minidump. Opened with the matching ja2.pdb in Visual Studio / WinDbg it gives the full symbolic stack, locals and all threads.

A message box tells the player which two files to attach when reporting.

Coverage

  • SEH crashes (access violations, etc. — the common case) via SetUnhandledExceptionFilter.
  • CRT-fatal paths that bypass SEH — pure-virtual call, invalid CRT parameter, and abort()/SIGABRT (where an unhandled std::terminate also lands) — routed through the same writer via RtlCaptureContext.

Notes

  • Uses Dbghelp.lib (already linked); single file, no CMake change.
  • Hardened after review: writes the minidump before touching DbgHelp symbols (so a corrupt/locked loader list can't cost us the dump); reentrancy-guarded and __try-wrapped so the handler can't re-crash the report; reserves stack via SetThreadStackGuarantee (loaded dynamically for XP-era headers) so it still runs on a stack-overflow crash.
  • Writes to the game folder (matches the request); if that folder isn't writable the report is skipped (message box still shows). A %TEMP% fallback could be added later.
  • Windows/MSVC project — reviewed for MSVC compile-ability + DbgHelp correctness; validated by the branch CI build.

🤖 Generated with Claude Code

The shipped build has no crash reporting - the __try/__except around the game
is behind ENABLE_EXCEPTION_HANDLING, which is never defined, so an unhandled
exception just terminates the process with no diagnostics, making player crash
reports unactionable.

Install a top-level crash handler as the first thing in WinMain
(SetUnhandledExceptionFilter, plus CRT pure-virtual / invalid-parameter / abort
handlers). On any crash it writes two files to the game folder:

- CrashLog_<pid>.txt: readable summary - build version, time, exception type,
  faulting module+offset, access-violation address, and a symbolic call stack
  (function + file:line when a .pdb is present, module+offset otherwise).
- CrashDump_<pid>.dmp: a minidump; open it with the matching ja2.pdb in Visual
  Studio / WinDbg for a full symbolic stack, locals and all threads.

A message box tells the user which two files to attach. Uses Dbghelp.lib
(already linked). Hardened: writes the minidump before touching DbgHelp symbols,
reentrancy-guarded and __try-wrapped so it can't re-crash the report, reserves
stack (SetThreadStackGuarantee, dynamically loaded for XP headers) so it runs on
a stack-overflow crash.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant