How to make a dialog when panic by egui

I tried to call eframe::run_native in panic_hook after I created another egui window , I got this error .

My custom panic message

Panic !
Message   : already borrowed: BorrowMutError
Location  : File : "C:\Users\22375\.cargo\registry\src\mirrors.tuna.tsinghua.edu.cn-df7c3c540f42cdbd\eframe-0.24.0\src\native\run.rs" Line : 59 Column : 41
Thread    : main
Backtrace :
disabled backtrace

I think it is not possible to call egui::run_native() more than once.
Newer egui has a viewport but I think it is broken at the moment.

Yes , viewport also need to be updated , but after the thread panic , it will be no longer updated

This group helps better when you post code that produces error message.

You may consider using std::panic::catch_unwind to catch the panic inside your ui code so you're still in egui's context.

It sounds like a nice idea , maybe I can try it later .

Unluckily

impl eframe::App for MyApp {
    fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
        catch_unwind(|| {
            egui::CentralPanel::default().show(ctx, |ui| {
                if ui.button("Panic").clicked() {
                    panic!("Panic here !");
                }
            });
        })
        .unwrap_or_else(|e| {
            panic!()
        })
    }
}

The code will cause a compile error

error[E0277]: the type `UnsafeCell<egui::context::ContextImpl>` may contain interior mutability and a reference may not be safely transferrable across a catch_unwind boundary
   --> src\bin\panic_msg.rs:21:22
    |
21  |           catch_unwind(|| {
    |  _________------------_^
    | |         |
    | |         required by a bound introduced by this call
22  | |             egui::CentralPanel::default().show(ctx, |ui| {
23  | |                 if ui.button("Panic").clicked() {
24  | |                     panic!("Panic here !");
25  | |                 }
26  | |             });
27  | |         })
    | |_________^ `UnsafeCell<egui::context::ContextImpl>` may contain interior mutability and a reference may not be safely transferrable across a catch_unwind boundary
    |
    = help: within `eframe::egui::Context`, the trait `RefUnwindSafe` is not implemented for `UnsafeCell<egui::context::ContextImpl>`

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.