Using the Crash API

How is the crash api supposed to be used? Does it only work on device or will it work while running in the editor as well?

1 Like

Yes, that should work!

You can try it by generating a dummy crash log with:

local p = sys.get_save_file("CrashTest", "crash.bin")
crash.set_file_path(p)
crash.set_user_field(0, "Gurka123");
crash.write_dump()

Then, just to get an overview of what data you have available, do something like this:

function load()
    local d = crash.load_previous()
    if d == nil then
        print("No crash dump found")
        return
    end
    
    print("Crash [" .. crash.get_sys_field(d, crash.SYSFIELD_ENGINE_VERSION) .. "] [" .. crash.get_sys_field(d, crash.SYSFIELD_ENGINE_HASH) .. "]")
    print("Signum [" .. crash.get_signum(d) .. "]") 
    print("Userdata0 = [" .. crash.get_user_field(d, 0) .. "]")

    print("Modules:")
    pprint(crash.get_modules(d))

    print("Backtrace:")
    pprint(crash.get_backtrace(d))
    
    print("Pretty Backtrace:\n" .. crash.get_extra_data(d))

    crash.release(d)

end

load()

So is an equivalent to crash.write_dump() called automatically when a crash occurs?

1 Like

Ah, yup, that should be the case!

I am not getting this to work at all. I have a game that crashes on some devices, so in the main script (attached to a collection that never gets unloaded) I have added:

function init(self)
	local p = sys.get_save_file("CrashTest", "crash.bin")
	crash.set_file_path(p)
	load()
        ...
end

And the load function is exactly the same as yours above. Still, every time I start the application I get “No crash dump found” - even though a crash has occured the last time I ran.

Am I missing something?

Did you try by first removing the first two lines? They were just part of an example @sven made in order to test to read the data. I’m not sure about this, but it could be that you are currently setting the path to a different path which will be used in the later crash.load_previous call, and that path being different from the location where the engine wrote the actual crash dump to.

Hmmm… So I am not supposed to set the file path?