Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 26 additions & 15 deletions crates/freya-winit/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,32 @@ pub mod tray {
///
/// If a custom event loop was provided via [`LaunchConfig::with_event_loop`], it will be used.
/// Otherwise a default one is created.
pub fn launch(mut launch_config: LaunchConfig) {
pub fn launch(launch_config: LaunchConfig) {
#[cfg(all(not(debug_assertions), not(target_os = "android")))]
{
let run_result = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| {
launch_inner(launch_config);
}));
if let Err(panic_payload) = run_result {
let description = panic_payload
.downcast_ref::<&str>()
.map(|message| message.to_string())
.or_else(|| panic_payload.downcast_ref::<String>().cloned())
.unwrap_or_else(|| "The application panicked.".to_string());
rfd::MessageDialog::new()
.set_title("Fatal Error")
.set_description(&description)
.set_level(rfd::MessageLevel::Error)
.show();
std::process::exit(1);
}
}

#[cfg(any(debug_assertions, target_os = "android"))]
launch_inner(launch_config);
}

fn launch_inner(mut launch_config: LaunchConfig) {
use std::collections::HashMap;

use freya_core::integration::*;
Expand All @@ -59,20 +84,6 @@ pub fn launch(mut launch_config: LaunchConfig) {
};
use winit::event_loop::EventLoop;

#[cfg(all(not(debug_assertions), not(target_os = "android")))]
{
let previous_hook = std::panic::take_hook();
std::panic::set_hook(Box::new(move |panic_info| {
rfd::MessageDialog::new()
.set_title("Fatal Error")
.set_description(&panic_info.to_string())
.set_level(rfd::MessageLevel::Error)
.show();
previous_hook(panic_info);
std::process::exit(1);
}));
}

let event_loop = launch_config.event_loop.take().unwrap_or_else(|| {
EventLoop::<NativeEvent>::with_user_event()
.build()
Expand Down
Loading