Skip to main content

gizmo_app/
lib.rs

1#[cfg(feature = "editor")]
2pub mod dev_console;
3pub mod plugin;
4
5pub use plugin::Plugin;
6
7#[cfg(feature = "window")]
8pub mod windowed;
9#[cfg(feature = "window")]
10pub use windowed::*;
11
12#[cfg(not(feature = "window"))]
13pub mod headless;
14#[cfg(not(feature = "window"))]
15pub use headless::*;
16
17pub fn setup_panic_hook() {
18    #[cfg(target_arch = "wasm32")]
19    {
20        console_error_panic_hook::set_once();
21        let _ = console_log::init_with_level(log::Level::Debug);
22        let _ = tracing_wasm::try_set_as_global_default();
23    }
24    #[cfg(not(target_arch = "wasm32"))]
25    {
26        std::panic::set_hook(Box::new(|panic_info| {
27            let message = if let Some(s) = panic_info.payload().downcast_ref::<&str>() {
28                *s
29            } else if let Some(s) = panic_info.payload().downcast_ref::<String>() {
30                s.as_str()
31            } else {
32                "Bilinmeyen hata"
33            };
34
35            let location = if let Some(loc) = panic_info.location() {
36                format!("{}:{}", loc.file(), loc.line())
37            } else {
38                "Bilinmeyen konum".to_string()
39            };
40
41            let error_msg = format!("Gizmo Engine Coktu!\n\nKonum: {}\nHata: {}\n", location, message);
42            tracing::error!("{}", error_msg);
43
44            #[cfg(feature = "window")]
45            {
46                let backtrace = backtrace::Backtrace::new();
47                tracing::info!("--- BACKTRACE ---\n{:?}", backtrace);
48                rfd::MessageDialog::new()
49                    .set_title("Gizmo Engine Fatal Error")
50                    .set_description(&error_msg)
51                    .set_level(rfd::MessageLevel::Error)
52                    .show();
53            }
54        }));
55    }
56}