Compare commits
2 commits
master
...
refactor-w
Author | SHA1 | Date | |
---|---|---|---|
![]() |
2f6f3b652c | ||
![]() |
aee64eed70 |
1 changed files with 6 additions and 5 deletions
|
@ -465,13 +465,14 @@ impl EventToUnsubscribe {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Helper used when registering events.
|
||||||
pub struct AppRunnerContainer {
|
pub struct AppRunnerContainer {
|
||||||
pub runner: AppRunnerRef,
|
pub runner: AppRunnerRef,
|
||||||
|
|
||||||
/// Set to `true` if there is a panic.
|
/// Set to `true` if there is a panic.
|
||||||
/// Used to ignore callbacks after a panic.
|
/// Used to ignore callbacks after a panic.
|
||||||
pub panicked: Arc<AtomicBool>,
|
pub panicked: Arc<AtomicBool>,
|
||||||
pub events: Vec<EventToUnsubscribe>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AppRunnerContainer {
|
impl AppRunnerContainer {
|
||||||
|
@ -511,7 +512,10 @@ impl AppRunnerContainer {
|
||||||
closure,
|
closure,
|
||||||
};
|
};
|
||||||
|
|
||||||
self.events.push(EventToUnsubscribe::TargetEvent(handle));
|
self.runner
|
||||||
|
.lock()
|
||||||
|
.events_to_unsubscribe
|
||||||
|
.push(EventToUnsubscribe::TargetEvent(handle));
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -542,7 +546,6 @@ fn start_runner(app_runner: AppRunner) -> Result<AppRunnerRef, JsValue> {
|
||||||
let mut runner_container = AppRunnerContainer {
|
let mut runner_container = AppRunnerContainer {
|
||||||
runner: Arc::new(Mutex::new(app_runner)),
|
runner: Arc::new(Mutex::new(app_runner)),
|
||||||
panicked: Arc::new(AtomicBool::new(false)),
|
panicked: Arc::new(AtomicBool::new(false)),
|
||||||
events: Vec::with_capacity(20),
|
|
||||||
};
|
};
|
||||||
|
|
||||||
super::events::install_canvas_events(&mut runner_container)?;
|
super::events::install_canvas_events(&mut runner_container)?;
|
||||||
|
@ -554,8 +557,6 @@ fn start_runner(app_runner: AppRunner) -> Result<AppRunnerRef, JsValue> {
|
||||||
// Disable all event handlers on panic
|
// Disable all event handlers on panic
|
||||||
let previous_hook = std::panic::take_hook();
|
let previous_hook = std::panic::take_hook();
|
||||||
|
|
||||||
runner_container.runner.lock().events_to_unsubscribe = runner_container.events;
|
|
||||||
|
|
||||||
std::panic::set_hook(Box::new(move |panic_info| {
|
std::panic::set_hook(Box::new(move |panic_info| {
|
||||||
tracing::info!("egui disabled all event handlers due to panic");
|
tracing::info!("egui disabled all event handlers due to panic");
|
||||||
runner_container.panicked.store(true, SeqCst);
|
runner_container.panicked.store(true, SeqCst);
|
||||||
|
|
Loading…
Reference in a new issue