Compare commits

...

2 commits

Author SHA1 Message Date
Emil Ernerfeldt
2f6f3b652c Add docstring 2022-11-18 16:23:16 +01:00
Emil Ernerfeldt
aee64eed70 Remove AppRunnerContainer::events 2022-11-18 16:23:16 +01:00

View file

@ -465,13 +465,14 @@ impl EventToUnsubscribe {
}
}
}
/// Helper used when registering events.
pub struct AppRunnerContainer {
pub runner: AppRunnerRef,
/// Set to `true` if there is a panic.
/// Used to ignore callbacks after a panic.
pub panicked: Arc<AtomicBool>,
pub events: Vec<EventToUnsubscribe>,
}
impl AppRunnerContainer {
@ -511,7 +512,10 @@ impl AppRunnerContainer {
closure,
};
self.events.push(EventToUnsubscribe::TargetEvent(handle));
self.runner
.lock()
.events_to_unsubscribe
.push(EventToUnsubscribe::TargetEvent(handle));
Ok(())
}
@ -542,7 +546,6 @@ fn start_runner(app_runner: AppRunner) -> Result<AppRunnerRef, JsValue> {
let mut runner_container = AppRunnerContainer {
runner: Arc::new(Mutex::new(app_runner)),
panicked: Arc::new(AtomicBool::new(false)),
events: Vec::with_capacity(20),
};
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
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| {
tracing::info!("egui disabled all event handlers due to panic");
runner_container.panicked.store(true, SeqCst);