Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Warn when WindowDescriptor is inserted after adding WindowPlugin. #5885

Closed
wants to merge 5 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions crates/bevy_window/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ mod window;
mod windows;

pub use crate::raw_window_handle::*;
use bevy_utils::tracing::warn;
pub use cursor::*;
pub use event::*;
pub use system::*;
Expand All @@ -25,7 +26,7 @@ use bevy_app::prelude::*;
use bevy_ecs::{
event::Events,
schedule::{ParallelSystemDescriptorCoercion, SystemLabel},
system::Resource,
system::{Res, Resource},
};

/// The configuration information for the [`WindowPlugin`].
Expand Down Expand Up @@ -99,8 +100,7 @@ impl Plugin for WindowPlugin {
if settings.add_primary_window {
let window_descriptor = app
.world
.get_resource::<WindowDescriptor>()
.cloned()
.remove_resource::<WindowDescriptor>()
tim-blackbird marked this conversation as resolved.
Show resolved Hide resolved
.unwrap_or_default();
let mut create_window_event = app.world.resource_mut::<Events<CreateWindow>>();
create_window_event.send(CreateWindow {
Expand All @@ -118,6 +118,18 @@ impl Plugin for WindowPlugin {
if settings.close_when_requested {
app.add_system(close_when_requested);
}

#[cfg(debug_assertions)]
app.add_system(|wd: Option<Res<WindowDescriptor>>| {
if let Some(wd) = wd {
if wd.is_added() {
warn!(
"The WindowDescriptor resource must be inserted before the WindowPlugin is added. \
Make sure to insert WindowDescriptor before adding the DefaultPlugins or the WindowPlugin.",
);
}
}
});
}
}

Expand Down