Skip to content

Commit

Permalink
13743 app exit hang (bevyengine#13744)
Browse files Browse the repository at this point in the history
Fixes bevyengine#13743.

---------

Co-authored-by: Brezak <bezak.adam@proton.me>
  • Loading branch information
tychedelia and Brezak committed Jun 8, 2024
1 parent 3bfc427 commit 7b14b8c
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion crates/bevy_winit/src/system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ use bevy_window::{
use winit::dpi::{LogicalPosition, LogicalSize, PhysicalPosition, PhysicalSize};
use winit::event_loop::ActiveEventLoop;

use bevy_app::AppExit;
use bevy_ecs::prelude::EventReader;
use bevy_ecs::query::With;
#[cfg(target_os = "ios")]
use winit::platform::ios::WindowExtIOS;
Expand Down Expand Up @@ -116,14 +118,16 @@ pub fn create_windows<F: QueryFilter + 'static>(
}
}

#[allow(clippy::too_many_arguments)]
pub(crate) fn despawn_windows(
closing: Query<Entity, With<ClosingWindow>>,
mut closed: RemovedComponents<Window>,
window_entities: Query<&Window>,
window_entities: Query<Entity, With<Window>>,
mut closing_events: EventWriter<WindowClosing>,
mut closed_events: EventWriter<WindowClosed>,
mut winit_windows: NonSendMut<WinitWindows>,
mut windows_to_drop: Local<Vec<WindowWrapper<winit::window::Window>>>,
mut exit_events: EventReader<AppExit>,
) {
// Drop all the windows that are waiting to be closed
windows_to_drop.clear();
Expand All @@ -146,6 +150,15 @@ pub(crate) fn despawn_windows(
closed_events.send(WindowClosed { window });
}
}

// On macOS, when exiting, we need to tell the rendering thread the windows are about to
// close to ensure that they are dropped on the main thread. Otherwise, the app will hang.
if !exit_events.is_empty() {
exit_events.clear();
for window in window_entities.iter() {
closing_events.send(WindowClosing { window });
}
}
}

/// The cached state of the window so we can check which properties were changed from within the app.
Expand Down

0 comments on commit 7b14b8c

Please sign in to comment.