Fix macOS race condition when closing window

This commit is contained in:
Héctor Ramón Jiménez 2024-07-24 12:18:53 +02:00
parent 884c66ca15
commit a5b1a1df54
No known key found for this signature in database
GPG key ID: 4C07CEC81AFA161F

View file

@ -320,7 +320,6 @@ where
.send(Boot { .send(Boot {
compositor, compositor,
clipboard, clipboard,
window: window.id(),
}) })
.ok() .ok()
.expect("Send boot event"); .expect("Send boot event");
@ -601,9 +600,9 @@ where
struct Boot<C> { struct Boot<C> {
compositor: C, compositor: C,
clipboard: Clipboard, clipboard: Clipboard,
window: winit::window::WindowId,
} }
#[derive(Debug)]
enum Event<Message: 'static> { enum Event<Message: 'static> {
WindowCreated { WindowCreated {
id: window::Id, id: window::Id,
@ -615,6 +614,7 @@ enum Event<Message: 'static> {
EventLoopAwakened(winit::event::Event<Message>), EventLoopAwakened(winit::event::Event<Message>),
} }
#[derive(Debug)]
enum Control { enum Control {
ChangeFlow(winit::event_loop::ControlFlow), ChangeFlow(winit::event_loop::ControlFlow),
Exit, Exit,
@ -647,10 +647,10 @@ async fn run_instance<P, C>(
let Boot { let Boot {
mut compositor, mut compositor,
mut clipboard, mut clipboard,
window: boot_window,
} = boot.try_recv().ok().flatten().expect("Receive boot"); } = boot.try_recv().ok().flatten().expect("Receive boot");
let mut window_manager = WindowManager::new(); let mut window_manager = WindowManager::new();
let mut boot_window_closed = false;
let mut events = Vec::new(); let mut events = Vec::new();
let mut messages = Vec::new(); let mut messages = Vec::new();
@ -926,9 +926,8 @@ async fn run_instance<P, C>(
window_event, window_event,
winit::event::WindowEvent::Destroyed winit::event::WindowEvent::Destroyed
) )
&& window_id != boot_window
&& window_manager.is_empty()
{ {
if boot_window_closed && window_manager.is_empty() {
control_sender control_sender
.start_send(Control::Exit) .start_send(Control::Exit)
.expect("Send control action"); .expect("Send control action");
@ -936,6 +935,9 @@ async fn run_instance<P, C>(
continue; continue;
} }
boot_window_closed = true;
}
let Some((id, window)) = let Some((id, window)) =
window_manager.get_mut_alias(window_id) window_manager.get_mut_alias(window_id)
else { else {