diff options
Diffstat (limited to 'ctr-std/src/panicking.rs')
| -rw-r--r-- | ctr-std/src/panicking.rs | 36 |
1 files changed, 27 insertions, 9 deletions
diff --git a/ctr-std/src/panicking.rs b/ctr-std/src/panicking.rs index 4030562..ad0a337 100644 --- a/ctr-std/src/panicking.rs +++ b/ctr-std/src/panicking.rs @@ -76,9 +76,7 @@ static mut HOOK: Hook = Hook::Default; /// is invoked. As such, the hook will run with both the aborting and unwinding /// runtimes. The default hook prints a message to standard error and generates /// a backtrace if requested, but this behavior can be customized with the -/// `set_hook` and [`take_hook`] functions. -/// -/// [`take_hook`]: ./fn.take_hook.html +/// `set_hook` and `take_hook` functions. /// /// The hook is provided with a `PanicInfo` struct which contains information /// about the origin of the panic, including the payload passed to `panic!` and @@ -123,10 +121,6 @@ pub fn set_hook(hook: Box<Fn(&PanicInfo) + 'static + Sync + Send>) { /// Unregisters the current panic hook, returning it. /// -/// *See also the function [`set_hook`].* -/// -/// [`set_hook`]: ./fn.set_hook.html -/// /// If no custom hook is registered, the default hook will be returned. /// /// # Panics @@ -197,9 +191,33 @@ fn default_hook(info: &PanicInfo) { let thread = thread_info::current_thread(); let name = thread.as_ref().and_then(|t| t.name()).unwrap_or("<unnamed>"); + // 3DS-specific code begins here to display panics via the Error applet + use libctru::{errorInit, errorText, errorDisp, errorConf, ERROR_TEXT_WORD_WRAP, + CFG_LANGUAGE_EN, consoleDebugInit, debugDevice_SVC}; + + let error_text = format!("thread '{}' panicked at '{}', {}", name, msg, location); + + unsafe { + // Prepare error message for display + let mut error_conf: errorConf = mem::uninitialized(); + errorInit(&mut error_conf, + ERROR_TEXT_WORD_WRAP, + CFG_LANGUAGE_EN); + errorText(&mut error_conf, error_text.as_ptr() as *const ::libc::c_char); + + // Display the error + errorDisp(&mut error_conf); + } + + // Let's also write to stderr using the debug console. The output will be + // visible in Citra if a custom logging filter such as `Debug.Emulated:Debug` + // is enabled in the logging section of `~/.config/citra-emu/sdl2-config.ini` + unsafe { + consoleDebugInit(debugDevice_SVC); + } + let write = |err: &mut ::io::Write| { - let _ = writeln!(err, "thread '{}' panicked at '{}', {}", - name, msg, location); + let _ = write!(err, "{}", error_text); #[cfg(feature = "backtrace")] { |