Skip to content

Move Window creation from plugin build time to PreStartup #20019

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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
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
19 changes: 11 additions & 8 deletions crates/bevy_window/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ extern crate alloc;

use alloc::sync::Arc;

use bevy_ecs::system::Commands;
use bevy_platform::sync::Mutex;

mod event;
Expand Down Expand Up @@ -130,14 +131,16 @@ impl Plugin for WindowPlugin {
.add_event::<AppLifecycle>();

if let Some(primary_window) = &self.primary_window {
let mut entity_commands = app.world_mut().spawn(primary_window.clone());
entity_commands.insert((
PrimaryWindow,
RawHandleWrapperHolder(Arc::new(Mutex::new(None))),
));
if let Some(primary_cursor_options) = &self.primary_cursor_options {
entity_commands.insert(primary_cursor_options.clone());
}
let primary_window = primary_window.clone();
let primary_cursor_options = self.primary_cursor_options.clone().unwrap_or_default();
Copy link
Member Author

@janhohenheim janhohenheim Jul 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the same behavior as before because CursorOptions is a required component of Window

app.add_systems(PreStartup, move |mut commands: Commands| {
commands.spawn((
primary_window.clone(),
PrimaryWindow,
RawHandleWrapperHolder(Arc::new(Mutex::new(None))),
primary_cursor_options.clone(),
));
});
}

match self.exit_condition {
Expand Down