diff --git a/crates/bevy_window/src/system.rs b/crates/bevy_window/src/system.rs index e29cf48bf7953..80e9170c5c93c 100644 --- a/crates/bevy_window/src/system.rs +++ b/crates/bevy_window/src/system.rs @@ -1,4 +1,4 @@ -use crate::{PrimaryWindow, Window, WindowCloseRequested, WindowClosed, WindowFocus}; +use crate::{PrimaryWindow, Window, WindowCloseRequested, WindowFocus}; use bevy_app::AppExit; use bevy_ecs::prelude::*; diff --git a/crates/bevy_winit/src/lib.rs b/crates/bevy_winit/src/lib.rs index e100af6ef8654..ee6f0a462ef26 100644 --- a/crates/bevy_winit/src/lib.rs +++ b/crates/bevy_winit/src/lib.rs @@ -69,7 +69,7 @@ impl Plugin for WinitPlugin { .with_system(update_cursor_position) .with_system(update_resize_constraints), ) - .add_system_to_stage(CoreStage::Last, despawn_window); + .add_system_to_stage(CoreStage::PreUpdate, despawn_window); #[cfg(target_arch = "wasm32")] app.add_plugin(web_resize::CanvasParentResizePlugin); @@ -238,6 +238,7 @@ pub fn winit_runner(mut app: App) { // TODO move all system state fetch up here? if let Some(app_exit_events) = app.world.get_resource::>() { if app_exit_event_reader.iter(app_exit_events).last().is_some() { + warn!("exitting"); *control_flow = ControlFlow::Exit; return; } diff --git a/crates/bevy_winit/src/system.rs b/crates/bevy_winit/src/system.rs index 41d7b7adec55b..4f680bd50b3af 100644 --- a/crates/bevy_winit/src/system.rs +++ b/crates/bevy_winit/src/system.rs @@ -2,7 +2,8 @@ use bevy_ecs::{ entity::{Entities, Entity}, event::EventWriter, prelude::{Added, Changed, With}, - system::{Commands, NonSendMut, Query, RemovedComponents, Res}, + removal_detection::RemovedComponent, + system::{Commands, NonSendMut, Query, Res}, }; use bevy_utils::tracing::{error, info}; use bevy_window::{ @@ -62,19 +63,21 @@ pub fn despawn_window( mut commands: Commands, entities: &Entities, primary: Option>, - closed: RemovedComponents, + mut closed: RemovedComponent, mut close_events: EventWriter, mut winit_windows: NonSendMut, ) { for window in closed.iter() { + info!("closing window: {:?}", window); winit_windows.remove_window(window); - if entities.contains(window) { - commands.entity(window).despawn(); - } + //if entities.contains(window) { + //commands.entity(window).despawn(); + //} if let Some(ref primary) = primary { if primary.window == window { + info!("removing primary"); commands.remove_resource::(); } } diff --git a/examples/ecs/removal_detection.rs b/examples/ecs/removal_detection.rs index f931066a4a4ec..82f04f0be1f26 100644 --- a/examples/ecs/removal_detection.rs +++ b/examples/ecs/removal_detection.rs @@ -51,7 +51,7 @@ fn remove_component( } } -fn react_on_removal(removed: RemovedComponents, mut query: Query<&mut Sprite>) { +fn react_on_removal(mut removed: RemovedComponent, mut query: Query<&mut Sprite>) { // `RemovedComponents::iter()` returns an interator with the `Entity`s that had their // `Component` `T` (in this case `MyComponent`) removed at some point earlier during the frame. for entity in removed.iter() { diff --git a/examples/window/multiple_windows.rs b/examples/window/multiple_windows.rs index aef27a8196946..fd886f644b859 100644 --- a/examples/window/multiple_windows.rs +++ b/examples/window/multiple_windows.rs @@ -13,6 +13,7 @@ fn main() { // A window bundle inserted as a resource acts as the descriptor // for a primary window. .insert_resource(WindowBundle::default()) + .insert_resource(RemovedComponents::default()) .add_startup_system(setup_scene) .add_startup_system(setup_extra_windows) .add_system(bevy::window::close_on_esc) @@ -51,7 +52,7 @@ fn setup_extra_windows(mut commands: Commands) { .spawn_bundle(WindowBundle { title: WindowTitle::new("Second window"), // A window can start minimized. - state: WindowState::Minimized, + //state: WindowState::Minimized, ..Default::default() }) .id();