Skip to content

Commit

Permalink
Update private.rs
Browse files Browse the repository at this point in the history
  • Loading branch information
Ughuuu committed Sep 9, 2024
1 parent 5e674ae commit 5fb39df
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions godot-core/src/private.rs
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,7 @@ fn report_call_error(call_error: CallError, track_globally: bool) -> i32 {
0
}
}

fn handle_panic_with_print<E, F, R, S>(error_context: E, code: F, print: bool) -> Result<R, String>
where
E: FnOnce() -> S,
Expand All @@ -329,22 +330,21 @@ where
{
let info: Arc<Mutex<Option<GodotPanicInfo>>> = Arc::new(Mutex::new(None));

// Back up previous hook, set new one
#[cfg(debug_assertions)]
let prev_hook = {
let info = info.clone();
// Back up previous hook, set new one
let prev_hook = std::panic::take_hook();

std::panic::set_hook(Box::new(move |panic_info| {
if let Some(location) = panic_info.location() {
*info.lock().unwrap() = Some(GodotPanicInfo {
file: location.file().to_string(),
line: location.line(),
// Uncomment if you want backtrace here
// backtrace: Backtrace::capture(),
});
} else {
eprintln!("panic occurred, but no location information available");
eprintln!("panic occurred, but can't get location information");
}
}));

Expand Down Expand Up @@ -378,7 +378,6 @@ where
info.line,
error_context()
);
// Uncomment if using backtrace
// eprintln!("Backtrace:\n{}", info.backtrace);
}
}
Expand Down

0 comments on commit 5fb39df

Please sign in to comment.