mirror of
https://github.com/doukutsu-rs/doukutsu-rs
synced 2024-11-21 21:22:44 +00:00
Add panic logging
This commit is contained in:
parent
08f086bfc4
commit
ca5361cc58
|
@ -4,6 +4,7 @@ description = "A re-implementation of Cave Story (Doukutsu Monogatari) engine"
|
|||
version = "0.101.0"
|
||||
authors = ["Alula", "dawnDus"]
|
||||
edition = "2021"
|
||||
rust-version = "1.65"
|
||||
|
||||
[lib]
|
||||
crate-type = ["lib"]
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
use std::backtrace::Backtrace;
|
||||
use std::cell::UnsafeCell;
|
||||
use std::panic::PanicInfo;
|
||||
use std::path::PathBuf;
|
||||
use std::sync::Mutex;
|
||||
use std::time::{Duration, Instant};
|
||||
|
@ -290,8 +292,21 @@ fn init_logger() -> GameResult {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
fn panic_hook(info: &PanicInfo<'_>) {
|
||||
let backtrace = Backtrace::force_capture();
|
||||
let msg = info.payload().downcast_ref::<&str>().unwrap_or(&"");
|
||||
let location = info.location();
|
||||
|
||||
if location.is_some() {
|
||||
log::error!("Panic occurred in {} with message: '{msg}'\n {backtrace:#}", location.unwrap().to_string());
|
||||
} else {
|
||||
log::error!("Panic occurred with message: '{msg}'\n {backtrace:#}");
|
||||
}
|
||||
}
|
||||
|
||||
pub fn init(options: LaunchOptions) -> GameResult {
|
||||
let _ = init_logger();
|
||||
std::panic::set_hook(Box::new(panic_hook));
|
||||
|
||||
let mut context = Box::pin(Context::new());
|
||||
|
||||
|
|
Loading…
Reference in a new issue