Drop application handler on run loop exit (#4149)

Calling the `Drop` impl of the user's `ApplicationHandler` is important on
iOS and Web, since they don't return from `EventLoop::run_app`.

And now that we reliably call `Drop`, the `ApplicationHandler::exited`
event/callback is unnecessary; using `Drop` composes much better (open files
etc. stored in the app state will be automatically flushed), and prevents
weirdness like attempting to create a new window while exiting.
This commit is contained in:
Mads Marquart
2025-03-17 10:56:00 +01:00
committed by GitHub
parent ef37b1d5dd
commit afb731bb52
19 changed files with 170 additions and 137 deletions

View File

@@ -158,7 +158,6 @@ impl Runner {
Event::Resumed => self.app.resumed(&self.event_loop),
Event::CreateSurfaces => self.app.can_create_surfaces(&self.event_loop),
Event::AboutToWait => self.app.about_to_wait(&self.event_loop),
Event::LoopExiting => self.app.exiting(&self.event_loop),
}
}
}
@@ -639,7 +638,9 @@ impl Shared {
self.apply_control_flow();
// We don't call `handle_loop_destroyed` here because we don't need to
// perform cleanup when the Web browser is going to destroy the page.
self.handle_event(Event::LoopExiting);
//
// We do want to run the application handler's `Drop` impl.
*self.0.runner.borrow_mut() = RunnerEnum::Destroyed;
}
// handle_event takes in events and either queues them or applies a callback
@@ -737,7 +738,6 @@ impl Shared {
}
fn handle_loop_destroyed(&self) {
self.handle_event(Event::LoopExiting);
let all_canvases = std::mem::take(&mut *self.0.all_canvases.borrow_mut());
*self.0.page_transition_event_handle.borrow_mut() = None;
*self.0.on_mouse_move.borrow_mut() = None;
@@ -879,6 +879,5 @@ pub(crate) enum Event {
CreateSurfaces,
Resumed,
AboutToWait,
LoopExiting,
UserWakeUp,
}