From db5445b1a1a6b4306a8c20e208aedca24a17e45c Mon Sep 17 00:00:00 2001 From: Jonty Date: Mon, 22 Jan 2024 21:30:37 +0000 Subject: [PATCH] Attempt to write panics to file instead of just console. Also abort with an 0x04 address on windows - deadbeef seems to make things sad --- src/lib.rs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 729ee7e..fefe13e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -14,6 +14,7 @@ pub mod sound; pub mod sprite; pub mod system; +use alloc::format; use { crate::{ display::Display, @@ -307,6 +308,15 @@ fn panic(#[allow(unused)] panic_info: &PanicInfo) -> ! { location.line() ) .expect("write"); + #[cfg(debug_assertions)] + { + // Try and save panic to file if built in debug mode + let fs = FileSystem::get(); + let panic_str = format!("{:?}", panic_info); + let file = fs.open("panic.txt", FileOptions::kFileWrite).unwrap(); + let _num_bytes_written = file.write(panic_str.as_bytes()).unwrap(); + file.flush().unwrap(); + } System::log_to_console(output.as_str()); } else { System::log_to_console("panic\0"); @@ -320,11 +330,12 @@ fn panic(#[allow(unused)] panic_info: &PanicInfo) -> ! { } #[cfg(not(target_os = "macos"))] { - abort_with_addr(0xdeadbeef); + abort_with_addr(0x04); } } use core::alloc::{GlobalAlloc, Layout}; +use crankstart_sys::FileOptions; pub(crate) struct PlaydateAllocator;