Skip to content

Commit

Permalink
Remove panic handler
Browse files Browse the repository at this point in the history
  • Loading branch information
Meziu committed Nov 22, 2023
1 parent ccc9dbf commit 39bd6c2
Show file tree
Hide file tree
Showing 28 changed files with 0 additions and 93 deletions.
2 changes: 0 additions & 2 deletions ctru-rs/examples/audio-filters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ fn fill_buffer(audio_data: &mut [u8], frequency: f32) {
}

fn main() {
ctru::use_panic_handler();

let gfx = Gfx::new().expect("Couldn't obtain GFX controller");
let mut hid = Hid::new().expect("Couldn't obtain HID controller");
let apt = Apt::new().expect("Couldn't obtain APT controller");
Expand Down
2 changes: 0 additions & 2 deletions ctru-rs/examples/buttons.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
use ctru::prelude::*;

fn main() {
ctru::use_panic_handler();

let apt = Apt::new().unwrap();
let mut hid = Hid::new().unwrap();
let gfx = Gfx::new().unwrap();
Expand Down
2 changes: 0 additions & 2 deletions ctru-rs/examples/camera-image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ use std::time::Duration;
const WAIT_TIMEOUT: Duration = Duration::from_millis(300);

fn main() {
ctru::use_panic_handler();

let apt = Apt::new().expect("Failed to initialize Apt service.");
let mut hid = Hid::new().expect("Failed to initialize Hid service.");
let gfx = Gfx::new().expect("Failed to initialize GFX service.");
Expand Down
2 changes: 0 additions & 2 deletions ctru-rs/examples/file-explorer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ use std::os::horizon::fs::MetadataExt;
use std::path::{Path, PathBuf};

fn main() {
ctru::use_panic_handler();

let apt = Apt::new().unwrap();
let mut hid = Hid::new().unwrap();
let gfx = Gfx::new().unwrap();
Expand Down
2 changes: 0 additions & 2 deletions ctru-rs/examples/futures-basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ use futures::StreamExt;
use std::os::horizon::thread::BuilderExt;

fn main() {
ctru::use_panic_handler();

let gfx = Gfx::new().expect("Couldn't obtain GFX controller");
let mut hid = Hid::new().expect("Couldn't obtain HID controller");
let apt = Apt::new().expect("Couldn't obtain APT controller");
Expand Down
2 changes: 0 additions & 2 deletions ctru-rs/examples/futures-tokio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ use std::os::horizon::thread::BuilderExt;
use std::time::Duration;

fn main() {
ctru::use_panic_handler();

let gfx = Gfx::new().expect("Couldn't obtain GFX controller");
let mut hid = Hid::new().expect("Couldn't obtain HID controller");
let apt = Apt::new().expect("Couldn't obtain APT controller");
Expand Down
2 changes: 0 additions & 2 deletions ctru-rs/examples/gfx-3d-mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ const IMAGE: &[u8] = include_bytes!("assets/ferris.rgb");
static ZERO: &[u8] = &[0; IMAGE.len()];

fn main() {
ctru::use_panic_handler();

let gfx = Gfx::new().expect("Couldn't obtain GFX controller");
let mut hid = Hid::new().expect("Couldn't obtain HID controller");
let apt = Apt::new().expect("Couldn't obtain APT controller");
Expand Down
2 changes: 0 additions & 2 deletions ctru-rs/examples/gfx-bitmap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ use ctru::services::gfx::{Flush, Screen, Swap};
static IMAGE: &[u8] = include_bytes!("assets/ferris.rgb");

fn main() {
ctru::use_panic_handler();

let gfx = Gfx::new().expect("Couldn't obtain GFX controller");
let mut hid = Hid::new().expect("Couldn't obtain HID controller");
let apt = Apt::new().expect("Couldn't obtain APT controller");
Expand Down
2 changes: 0 additions & 2 deletions ctru-rs/examples/gfx-wide-mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
use ctru::prelude::*;

fn main() {
ctru::use_panic_handler();

let apt = Apt::new().unwrap();
let mut hid = Hid::new().unwrap();
let gfx = Gfx::new().unwrap();
Expand Down
2 changes: 0 additions & 2 deletions ctru-rs/examples/hashmaps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
use ctru::prelude::*;

fn main() {
ctru::use_panic_handler();

// HashMaps generate hashes thanks to the 3DS' cryptografically secure generator.
// This generator is only active when activating the `PS` service.
// This service is automatically initialized.
Expand Down
2 changes: 0 additions & 2 deletions ctru-rs/examples/hello-both-screens.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
use ctru::prelude::*;

fn main() {
ctru::use_panic_handler();

let apt = Apt::new().unwrap();
let mut hid = Hid::new().unwrap();
let gfx = Gfx::new().unwrap();
Expand Down
1 change: 0 additions & 1 deletion ctru-rs/examples/hello-world.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use std::io::BufWriter;
fn main() {
// Setup the custom panic handler in case any errors arise.
// Thanks to it the user will get promptly notified of any panics.
ctru::use_panic_handler();

// Setup Graphics, Controller Inputs, Application runtime.
// These is standard setup any app would need.
Expand Down
2 changes: 0 additions & 2 deletions ctru-rs/examples/linear-memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ use ctru::linear::LinearAllocator;
use ctru::prelude::*;

fn main() {
ctru::use_panic_handler();

let gfx = Gfx::new().expect("Couldn't obtain GFX controller");
let mut hid = Hid::new().expect("Couldn't obtain HID controller");
let apt = Apt::new().expect("Couldn't obtain APT controller");
Expand Down
2 changes: 0 additions & 2 deletions ctru-rs/examples/mii-selector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ use ctru::applets::mii_selector::{Error, MiiSelector, Options};
use ctru::prelude::*;

fn main() {
ctru::use_panic_handler();

let gfx = Gfx::new().expect("Couldn't obtain GFX controller");
let mut hid = Hid::new().expect("Couldn't obtain HID controller");
let apt = Apt::new().expect("Couldn't obtain APT controller");
Expand Down
2 changes: 0 additions & 2 deletions ctru-rs/examples/movement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
use ctru::prelude::*;

fn main() {
ctru::use_panic_handler();

let gfx = Gfx::new().expect("Couldn't obtain GFX controller");
let mut hid = Hid::new().expect("Couldn't obtain HID controller");
let apt = Apt::new().expect("Couldn't obtain APT controller");
Expand Down
2 changes: 0 additions & 2 deletions ctru-rs/examples/network-sockets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ use std::net::{Shutdown, TcpListener};
use std::time::Duration;

fn main() {
ctru::use_panic_handler();

let gfx = Gfx::new().unwrap();
let mut hid = Hid::new().unwrap();
let apt = Apt::new().unwrap();
Expand Down
2 changes: 0 additions & 2 deletions ctru-rs/examples/output-3dslink.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
use ctru::prelude::*;

fn main() {
ctru::use_panic_handler();

let gfx = Gfx::new().expect("Couldn't obtain GFX controller");
let mut hid = Hid::new().expect("Couldn't obtain HID controller");
let apt = Apt::new().expect("Couldn't obtain APT controller");
Expand Down
2 changes: 0 additions & 2 deletions ctru-rs/examples/romfs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
use ctru::prelude::*;

fn main() {
ctru::use_panic_handler();

let gfx = Gfx::new().expect("Couldn't obtain GFX controller");
let mut hid = Hid::new().expect("Couldn't obtain HID controller");
let apt = Apt::new().expect("Couldn't obtain APT controller");
Expand Down
2 changes: 0 additions & 2 deletions ctru-rs/examples/software-keyboard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ use ctru::applets::swkbd::{Button, SoftwareKeyboard};
use ctru::prelude::*;

fn main() {
ctru::use_panic_handler();

let apt = Apt::new().unwrap();
let mut hid = Hid::new().unwrap();
let gfx = Gfx::new().unwrap();
Expand Down
2 changes: 0 additions & 2 deletions ctru-rs/examples/system-configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ use ctru::prelude::*;
use ctru::services::cfgu::Cfgu;

fn main() {
ctru::use_panic_handler();

let gfx = Gfx::new().expect("Couldn't obtain GFX controller");
let mut hid = Hid::new().expect("Couldn't obtain HID controller");
let apt = Apt::new().expect("Couldn't obtain APT controller");
Expand Down
2 changes: 0 additions & 2 deletions ctru-rs/examples/thread-basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ use std::os::horizon::thread::BuilderExt;
use std::time::Duration;

fn main() {
ctru::use_panic_handler();

let apt = Apt::new().unwrap();
let mut hid = Hid::new().unwrap();
let gfx = Gfx::new().unwrap();
Expand Down
2 changes: 0 additions & 2 deletions ctru-rs/examples/thread-info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ use ctru::prelude::*;
use std::os::horizon::thread::BuilderExt;

fn main() {
ctru::use_panic_handler();

let gfx = Gfx::new().expect("Couldn't obtain GFX controller");
let mut hid = Hid::new().expect("Couldn't obtain HID controller");
let apt = Apt::new().expect("Couldn't obtain APT controller");
Expand Down
2 changes: 0 additions & 2 deletions ctru-rs/examples/thread-locals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ std::thread_local! {
}

fn main() {
ctru::use_panic_handler();

let gfx = Gfx::new().expect("Couldn't obtain GFX controller");
gfx.top_screen.borrow_mut().set_wide_mode(true);
let mut hid = Hid::new().expect("Couldn't obtain HID controller");
Expand Down
2 changes: 0 additions & 2 deletions ctru-rs/examples/time-rtc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
use ctru::prelude::*;

fn main() {
ctru::use_panic_handler();

let gfx = Gfx::new().expect("Couldn't obtain GFX controller");
let mut hid = Hid::new().expect("Couldn't obtain HID controller");
let apt = Apt::new().expect("Couldn't obtain APT controller");
Expand Down
2 changes: 0 additions & 2 deletions ctru-rs/examples/title-info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ use ctru::services::am::Am;
use ctru::services::fs::FsMediaType;

fn main() {
ctru::use_panic_handler();

let gfx = Gfx::new().expect("Couldn't obtain GFX controller");
let mut hid = Hid::new().expect("Couldn't obtain HID controller");
let apt = Apt::new().expect("Couldn't obtain APT controller");
Expand Down
2 changes: 0 additions & 2 deletions ctru-rs/examples/touch-screen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
use ctru::prelude::*;

fn main() {
ctru::use_panic_handler();

let gfx = Gfx::new().expect("Couldn't obtain GFX controller");
let mut hid = Hid::new().expect("Couldn't obtain HID controller");
let apt = Apt::new().expect("Couldn't obtain APT controller");
Expand Down
3 changes: 0 additions & 3 deletions ctru-rs/src/console.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,6 @@ impl<'screen> Console<'screen> {
/// This function is used to check whether one of the two screens has an existing (and selected) [`Console`],
/// so that the program can be sure its output will be shown *somewhere*.
///
/// The main use of this is within the [`ctru::use_panic_handler()`](crate::use_panic_handler()) hook,
/// since it will only stop the program's execution if the user is able to see the panic information output on screen.
///
/// # Example
///
/// ```
Expand Down
39 changes: 0 additions & 39 deletions ctru-rs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,45 +56,6 @@ macro_rules! from_impl {
};
}

/// Activate the custom [`ctru-rs`](crate) panic handler.
///
/// With this implementation, the main thread will stop and try to print debug info to an available [`Console`](console::Console).
/// In case it fails to find an active [`Console`](console::Console) the program will just exit.
///
/// # Notes
///
/// When `test` is enabled, this function will not do anything, as its behaviour should be overridden by the `test` environment.
pub fn use_panic_handler() {
#[cfg(not(test))]
panic_hook_setup();
}

/// Internal protocol to activate the custom panic handler hook.
///
/// # Notes
///
/// When `test` is enabled, this function will be ignored.
#[cfg(not(test))]
fn panic_hook_setup() {
use std::panic::PanicInfo;

let main_thread = std::thread::current().id();

// Panic Hook setup
let default_hook = std::panic::take_hook();
let new_hook = Box::new(move |info: &PanicInfo| {
default_hook(info);

// Only for panics in the main thread
if main_thread == std::thread::current().id() && console::Console::exists() {
println!("\nThe software will exit in 5 seconds");

std::thread::sleep(std::time::Duration::from_secs(5));
}
});
std::panic::set_hook(new_hook);
}

pub mod applets;
pub mod console;
pub mod error;
Expand Down

0 comments on commit 39bd6c2

Please sign in to comment.