Crash logs - Grisgram/gml-raptor GitHub Wiki

A crash of your game is the worst thing, that can happen to you as a developer, and especially, when the game is already out on steam, you want as much information, about what happened, as you can legally get, especially the last log lines and hopefully a stack trace.

Raptor can not offer you a backend-server where you can send your crash-reports to, nor can it handle steam-, epic- or any other store backend for you.

But what raptor can do for you, is to collect information about a crash and hold it in a crash dump file, which you can pick up at the very next start of your game. What you do with that file, is totally up to you.

GameMaker offers a tool for us for this case, a so-called Game_Exception_Handler. This is a callback function that gets invoked instead of the default crash window, GameMaker shows. raptor makes use of this function and redirects unhandled exceptions to the

function Game_Exception_Handler(_unhandled)

which can be found in the Game_Exception_Handler script in the _GAME_SETUP_ folder of the project template.
It holds a default implentation, that writes the RingBuffer of the Logger Configuration out to a file. The filename is set through the CRASH_DUMP_FILENAME macro, which is set together with other startup-parameters in the Game_Configuration script.

That's spooky, can I turn it off?

Yes, you can, though I do not recommend it.
Together with the CRASH_DUMP_FILENAME, you also find a macro that enables/disables the crash dump handler based on configuration in the Game_Configuration script. By default, it is off on default-configuration, an on for all other configurations. You can disable it entirely with this macro:

// The crash dump handler can be found in the Game_Exception_Handler script
// It generates crash logs in the file specified below, when an unhandled exception occurs,
// that crashes your game
#macro USE_CRASHDUMP_HANDLER		false
#macro beta:USE_CRASHDUMP_HANDLER	true
#macro release:USE_CRASHDUMP_HANDLER	true
#macro CRASH_DUMP_FILENAME		$"{GAME_FILE_PREFIX}_crashdump.bin"

How can I send my crash logs?

This is totally up to you. Upload them to your server, copy them to some location on your player's computer and ask him to send you an email containing the dump, ... you have many options here.

I would like to show you a piece of code I use in my games on startup, to detect, whether there is a crash dump file available (so, the last session has crashed) and to perform an action with it.

This example also takes care about the weird file handling in html, if your game is published on itch. The code below should work for html games on itch and anywhere else.

I call this function in the onGameStart function of the Game_Configuration script, because at this moment, the loading indicator from the GameStarter startup room is still visible to the user, and I have some time, to do background action, like sending the report.

Caution

Take care about data security, GDPR (DSGVO), especially when you run your game in the european union. Data protection is no fun topic, so you either be 100% sure, that under no circumstances, any personal data is contained in your logs (not even the IPAddress!), or make sure, the user agreed to sending crash reports, before you send anything (with or without the user's knowledge)!
You do not want to be a target of european commission!
I will take no responsibility of what is in the log, when you transfer it to a server! Not even for logs written by raptor, as even the GDPR changes at some points every year and I can not control, which raptor version you are using!

function report_last_session_crash() {
	try {
		var crash_contents = undefined;
		var have_crash = false;
		if (IS_HTML) {
			crash_contents = file_read_text_file(CRASH_DUMP_FILENAME, FILE_CRYPT_KEY);
		} else {
			if (file_exists(CRASH_DUMP_FILENAME))
				crash_contents = file_read_text_file(CRASH_DUMP_FILENAME, FILE_CRYPT_KEY);
		}
		have_crash = !string_is_empty(crash_contents);

		if (have_crash) {
			ilog($"Found crash dump");
			// ... here's the point where you do something with the crash data
			// in my games, i do a http_post now and upload it to the backend of my server

			// Hello HTML world at itch... it can't delete files,
			// So, for html we just replace the crash with an empty string.
			if (IS_HTML)
				file_write_text_file(CRASH_DUMP_FILENAME, "");
			else
				file_delete(CRASH_DUMP_FILENAME);
		}
	} catch (__ignored) { } // Please don't crash while handling a crash...
}
⚠️ **GitHub.com Fallback** ⚠️