write a crash report when an assertion fails

Assertions ship in every configuration - Ja2/builddefines.h defines
FORCE_ASSERTS_ON unconditionally - so a player on a release build hits the
runtime error screen with a line and a file, and that is all anyone ever
gets. The crash handler that would have written a report never runs,
because an assertion faults nothing.

Raise a software exception from _FailMessage so it does. The code has the
customer bit set, the handler recognizes it, and the report carries the
assertion's line, file and message alongside the usual registers, module
table and frame chain, which symbolizes back to the assertion site. The
exception is swallowed again immediately: first-chance is all the handler
needs, and letting it travel further would kill a game that means to show
its error screen.

The dumper needed two adjustments to cope with an exception nobody faulted:
its one-report-per-address rule keys on the assertion's own file and line,
since every raise shares RaiseException's address, and the re-entry latch
is lifted in the __except, which is the only code that runs if writing a
report faults.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
Marco Antonio J. Costa
2026-07-31 16:51:06 -03:00
committed by majcosta
co-authored by Claude Opus 5
parent 06b115a293
commit 56e6873b80
4 changed files with 109 additions and 14 deletions
+12
View File
@@ -48,10 +48,22 @@ private:
struct _EXCEPTION_POINTERS;
// Assertion failures raise this software exception so they get the same crash
// report as a real fault. Bit 29 set marks it customer-defined, so it can never
// collide with a system code; the top two bits mark it an error.
#define SGP_EXCEPTION_ASSERT 0xE1A55E27
namespace sgp
{
void dumpStackTrace(vfs::String const& msg);
// Raise SGP_EXCEPTION_ASSERT and swallow it again, so the vectored crash
// handler writes a report for an assertion that never faults. Carries the
// assert's line, file and message (NULL for a plain Assert) as exception
// parameters.
void raiseAssertException(unsigned lineNum, const char* sourceFileName,
const char* message);
// Write a heap-free crash report (registers + a raw return-address backtrace)
// for the faulting context to a numbered crash_report file; symbolize it
// offline against the build's PDB. Call first-chance from a vectored handler.