Skip to main content

Module crash

Module crash 

Source
Expand description

Crash reports (ADR-0079): a panic hook that writes a shuyi_platform::crash::CrashReport through the game’s storage, which run installs before its first frame (AppConfig::crash).

The hook takes the one before it and calls it after writing, so the standard library’s message in a terminal and miniquad’s console line on the web stay. It reads the frame and the top screen run set (set_frame) and the last lines of the log (note_log), from statics, so a panic on another thread (the music’s worker) gets them too. A panic caught on purpose runs in quiet and writes nothing.

A report is fatal when the panic is on the thread that runs the game, the one run installs the hook from: on native run catches it and ends the process, or it is outside that catch and ends it itself; on the web every panic aborts. A panic on another thread (quad-snd’s own, on a machine with no sound device) is kept, and not offered to the game as a crash.

On native, run catches a panic of the game’s frame: it stops the sound, adds the game’s record of its play to the report (add_record) and ends the process with exit code 101, as an uncaught panic does, without calling the game’s system hook, so a game in a broken state never saves over a good save. On the web a panic aborts, so a web report has no record.

SHUYI_PANIC_AT_FRAME=<n>, read once by run on native in any build, panics at frame n on purpose (PANIC_ON_PURPOSE), for the tests.

Structs§

CrashReports
Whether run writes crash reports, and with what version of the game. Build it with CrashReports::new or CrashReports::off; a game sets AppConfig::crash to it.

Constants§

PANIC_ON_PURPOSE
The message of the panic SHUYI_PANIC_AT_FRAME asks for.

Functions§

add_record
Adds the game’s record of its play to the report the hook wrote last, and writes it again under the same key. A record over shuyi_platform::crash::RECORD_BYTES is left out, and the report’s log says so. Does nothing if no report was written.
install
Writes reports of every panic from now on, as reports says, each through a new storage from storage, then calls the hook that was there before. The thread it is called on is the game’s: a panic there is fatal, and one on any other thread isn’t. Installs nothing if reports keeps none. Called again, it changes what the hook does, and installs no second hook.
note_log
Keeps line of the log among the last LOG_LINES, for a report.
quiet
Runs f with reports off on this thread: a panic it catches on purpose is not a crash.
set_frame
The frame about to run (App::frame_number() + 1) and the screen on top as it starts, for a report.