diff --git a/CHANGELOG.md b/CHANGELOG.md index c9c4946..6c19da5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/). - Fixed passing of crash message `__furi_crash_implementation` - Allow no argument calls to `flipperzero_sys::crash!` and `flipperzero_sys::halt!` macros - `flipperzero_sys::furi::UnsafeRecord::open` now takes a `&'static CStr` +- Fixed overread when printing panic message to console +- Added short delay in panic handler so message can be seen on USB console before `furi_crash` ### Removed diff --git a/crates/rt/src/panic_handler.rs b/crates/rt/src/panic_handler.rs index eeb4f9c..3895232 100644 --- a/crates/rt/src/panic_handler.rs +++ b/crates/rt/src/panic_handler.rs @@ -1,7 +1,6 @@ //! Panic handler for Furi applications. //! This will print the panic info to stdout and then trigger a crash. -use core::ffi::c_char; use core::panic::PanicInfo; use flipperzero_sys as sys; @@ -21,24 +20,21 @@ pub fn panic(panic_info: &PanicInfo<'_>) -> ! { sys::__wrap_printf(c"\x1b[0;31mthread: '%s' paniced".as_ptr(), thread_name); if let Some(s) = panic_info.message().as_str() { - sys::__wrap_printf(c" at '%*s'".as_ptr(), s.len(), s.as_ptr() as *const c_char); + sys::__wrap_printf(c" at '%.*s'".as_ptr(), s.len(), s.as_ptr()); } if let Some(location) = panic_info.location() { let file = location.file(); let line = location.line(); - sys::__wrap_printf( - c", %*s:%u".as_ptr(), - file.len(), - file.as_ptr() as *const c_char, - line, - ); + sys::__wrap_printf(c", %.*s:%u".as_ptr(), file.len(), file.as_ptr(), line); } sys::__wrap_printf(c"\x1b[0m\r\n".as_ptr()); sys::furi_thread_stdout_flush(); - sys::furi_thread_yield(); // Allow console to flush + + // Ensure there's plenty of time to fully flush the console + sys::furi_delay_ms(500); sys::crash!("Rust panic") }