Mark the fact that it was a double panic in the fatal message

This commit is contained in:
Gwilym Inzani 2024-05-12 14:08:03 +01:00
parent 642c3c1b79
commit 8c2e079ec2

View file

@ -203,7 +203,7 @@ pub use {agb_alloc::ExternalAllocator, agb_alloc::InternalAllocator};
#[panic_handler] #[panic_handler]
#[allow(unused_must_use)] #[allow(unused_must_use)]
fn panic_implementation(info: &core::panic::PanicInfo) -> ! { fn panic_implementation(info: &core::panic::PanicInfo) -> ! {
avoid_double_panic(); avoid_double_panic(info);
use core::fmt::Write; use core::fmt::Write;
if let Some(mut mgba) = mgba::Mgba::new() { if let Some(mut mgba) = mgba::Mgba::new() {
@ -216,10 +216,16 @@ fn panic_implementation(info: &core::panic::PanicInfo) -> ! {
// If we panic during the panic handler, then there isn't much we can do any more. So this code // If we panic during the panic handler, then there isn't much we can do any more. So this code
// just infinite loops halting the CPU. // just infinite loops halting the CPU.
fn avoid_double_panic() { fn avoid_double_panic(info: &core::panic::PanicInfo) {
static IS_PANICKING: portable_atomic::AtomicBool = portable_atomic::AtomicBool::new(false); static IS_PANICKING: portable_atomic::AtomicBool = portable_atomic::AtomicBool::new(false);
if IS_PANICKING.load(portable_atomic::Ordering::SeqCst) { if IS_PANICKING.load(portable_atomic::Ordering::SeqCst) {
if let Some(mut mgba) = mgba::Mgba::new() {
let _ = mgba.print(
format_args!("Double panic: {info}"),
mgba::DebugLevel::Fatal,
);
}
loop { loop {
syscall::halt(); syscall::halt();
} }
@ -342,7 +348,7 @@ pub mod test_runner {
#[panic_handler] #[panic_handler]
fn panic_implementation(info: &core::panic::PanicInfo) -> ! { fn panic_implementation(info: &core::panic::PanicInfo) -> ! {
avoid_double_panic(); avoid_double_panic(info);
#[cfg(feature = "backtrace")] #[cfg(feature = "backtrace")]
let frames = backtrace::unwind_exception(); let frames = backtrace::unwind_exception();