Skip to content

Commit

Permalink
Display message box on panic in Windows
Browse files Browse the repository at this point in the history
There's no way to access command-line output in a Windows GUI app, so
try to display the panic message in a message box as a last resort.
  • Loading branch information
valadaptive committed Aug 3, 2024
1 parent 5389281 commit a4757bf
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions crates/gui/src/bin/ntsc-rs-standalone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,16 @@ use std::error::Error;
use gui::app::main::run;

fn main() -> Result<(), Box<dyn Error>> {
#[cfg(windows)]
std::panic::set_hook(Box::new(|info| {
let backtrace = std::backtrace::Backtrace::force_capture();
rfd::MessageDialog::new()
.set_buttons(rfd::MessageButtons::Ok)
.set_level(rfd::MessageLevel::Error)
.set_description(format!("{info}\n\nBacktrace:\n{backtrace}"))
.set_title("Error")
.show();
}));

run()
}

0 comments on commit a4757bf

Please sign in to comment.