Browse Source

Print panic backtrace and exit on command

pull/12/head
Andrea Ciliberti 3 years ago
parent
commit
22404a9f14
  1. 21
      ctru-rs/src/lib.rs

21
ctru-rs/src/lib.rs

@ -9,12 +9,31 @@ extern crate widestring;
extern crate ctru_sys as libctru; extern crate ctru_sys as libctru;
/// Call this somewhere to force Rust to link some required crates /// Call this somewhere to force Rust to link some required crates
/// (ex. pthread-3ds). The call doesn't need to execute, just exist. /// This is also a setup for some crate integration only available at runtime
/// ///
/// See https://github.com/rust-lang/rust/issues/47384 /// See https://github.com/rust-lang/rust/issues/47384
pub fn init() { pub fn init() {
linker_fix_3ds::init(); linker_fix_3ds::init();
pthread_3ds::init(); pthread_3ds::init();
use std::panic::PanicInfo;
// Panic Hook setup
let default_hook = std::panic::take_hook();
let new_hook = Box::new( move |info: &PanicInfo| {
println!("\x1b[1;31m\n--------------------------------------------------");
default_hook(info);
println!("\nPress SELECT to exit the software");
let hid = services::hid::Hid::init().unwrap();
loop {
hid.scan_input();
if hid.keys_down().contains(services::hid::KeyPad::KEY_SELECT) {
break;
}
}
});
std::panic::set_hook(new_hook);
} }
pub mod applets; pub mod applets;

Loading…
Cancel
Save