From 32d17e552a11c9618c8900354895d1950d6ca8e9 Mon Sep 17 00:00:00 2001 From: Andrea Ciliberti Date: Thu, 27 Jan 2022 16:26:30 +0100 Subject: [PATCH] Distinct behaviour for main and non-main threads --- ctru-rs/examples/thread-basic.rs | 2 +- ctru-rs/src/lib.rs | 21 ++++++++++++++------- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/ctru-rs/examples/thread-basic.rs b/ctru-rs/examples/thread-basic.rs index a96d15f..7657718 100644 --- a/ctru-rs/examples/thread-basic.rs +++ b/ctru-rs/examples/thread-basic.rs @@ -16,7 +16,7 @@ fn main() { let prio = thread::current().priority(); println!("Main thread prio: {}\n", prio); - + for ix in 0..3 { thread::Builder::new() .priority(prio - 1) diff --git a/ctru-rs/src/lib.rs b/ctru-rs/src/lib.rs index 23be6b8..6946231 100644 --- a/ctru-rs/src/lib.rs +++ b/ctru-rs/src/lib.rs @@ -11,20 +11,27 @@ pub fn init() { use std::panic::PanicInfo; + let main_thread = thread::current().id(); + // Panic Hook setup let default_hook = std::panic::take_hook(); let new_hook = Box::new(move |info: &PanicInfo| { - println!("\x1b[1;31m\n--------------------------------------------------"); + println!("\x1b[1;31m\n--------------------------------------------------"); // Red ANSI Color Code 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; + // Only for panics in the main thread + if main_thread == thread::current().id() { + 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; + } } } + println!("\x1b[1;37m\n"); // Get back to white }); std::panic::set_hook(new_hook); }