Browse Source

Enable old panic behavior for Citra

pull/10/head
Fenrir 8 years ago
parent
commit
cbe41e5304
  1. 3
      ctr-std/Cargo.toml
  2. 35
      ctr-std/src/panicking.rs

3
ctr-std/Cargo.toml

@ -15,3 +15,6 @@ default-features = false
[dependencies.ctru-sys] [dependencies.ctru-sys]
path = "../ctru-sys" path = "../ctru-sys"
[features]
citra = []

35
ctr-std/src/panicking.rs

@ -57,8 +57,37 @@ pub fn begin_panic_fmt(msg: &fmt::Arguments, file_line_col: &(&'static str, u32,
begin_panic(s, file_line_col); begin_panic(s, file_line_col);
} }
/// We don't have stack unwinding, so all we do is print the panic message // Citra doesn't support the Error applet yet
/// and then crash or hang the application #[cfg(feature = "citra")]
#[unstable(feature = "libstd_sys_internals",
reason = "used by the panic! macro",
issue = "0")]
#[inline(never)] #[cold]
pub fn begin_panic<M: Any + Send + Display>(msg: M, file_line_col: &(&'static str, u32, u32)) -> ! {
let msg = Box::new(msg);
let (file, line, col) = *file_line_col;
// 3DS-specific code begins here
use libctru::{consoleInit, gfxScreen_t};
unsafe {
// set up a new console, overwriting whatever was on the top screen
// before we started panicking
let _console = consoleInit(gfxScreen_t::GFX_TOP, ptr::null_mut());
println!("thread '{}' panicked at '{}', {}:{}:{}",
"<unnamed>", msg, file, line, col);
// Citra seems to ignore calls to svcExitProcess, and libc::abort()
// causes it to lock up and fill the console with endless debug statements.
// So instead of terminating the program, we just let it spin in the following
// loop. This means that any background threads might continue to run after
// this thread panics, but there's not a lot we can do about that currently.
loop { }
}
}
#[cfg(not(feature = "citra"))]
#[unstable(feature = "libstd_sys_internals", #[unstable(feature = "libstd_sys_internals",
reason = "used by the panic! macro", reason = "used by the panic! macro",
issue = "0")] issue = "0")]
@ -82,7 +111,7 @@ pub fn begin_panic<M: Any + Send + Display>(msg: M, file_line_col: &(&'static st
CFG_Language::CFG_LANGUAGE_EN); CFG_Language::CFG_LANGUAGE_EN);
errorText(&mut error_conf, error_text.as_ptr() as *const libc::c_char); errorText(&mut error_conf, error_text.as_ptr() as *const libc::c_char);
// Display error via Error applet // Display error
errorDisp(&mut error_conf); errorDisp(&mut error_conf);
// Now that we're all done printing, it's time to exit the program. // Now that we're all done printing, it's time to exit the program.

Loading…
Cancel
Save