Skip to content

Spawning Windows partially fails when there is no inital PrimaryWindow #21948

@1ace

Description

@1ace

Bevy version and features

Relevant system information

This is on wayland.

AdapterInfo { name: "Apple M2 (G14G B0)", vendor: 65541, device: 0, device_type: IntegratedGpu, driver: "Honeykrisp", driver_info: "Mesa 26.0.0-devel (git-ad2f112ac2)", backend: Vulkan }

What you did

I am trying to create windows dynamically, and there is no meaning in having an initial window in my app, so I tried to disable it.

To have a simple reproducer, let's take the code from examples/window/multiple_windows.rs, and apply the following change:

diff --git ./examples/window/multiple_windows.rs ./examples/window/multiple_windows.rs
index 46d4a708a5a04eb35de8..dcb7a42a33f8d20b6a48 100644
--- ./examples/window/multiple_windows.rs
+++ ./examples/window/multiple_windows.rs
@@ -5,7 +5,10 @@
 fn main() {
     App::new()
         // By default, a primary window gets spawned by `WindowPlugin`, contained in `DefaultPlugins`
-        .add_plugins(DefaultPlugins)
+        .add_plugins(DefaultPlugins.set(WindowPlugin {
+            primary_window: None,
+            ..default()
+        }))
         .add_systems(Startup, setup_scene)
         .run();
 }

The intent being that this would stop the primary window from being created, while the second window continues to be created a few lines below, and the end result is that exactly one window appears, and it's the second one.

What went wrong

Instead, no window appears, but the app keeps running, presumably because the condition of "is there any window left open applies, meaning that the window was created enough for that, but not enough to be visible.

Additional information

A workaround that works is to let the default window get created (by not overriding primary_window), and then immediately close it at startup:

app.add_systems(Startup, close_primary_window);
fn close_primary_window(
    mut commands: Commands,
    primary_window: Single<Entity, With<PrimaryWindow>>,
) {
    commands.entity(*primary_window).despawn();
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-WindowingPlatform-agnostic interface layer to run your app inC-BugAn unexpected or incorrect behaviorS-Needs-DesignThis issue requires design work to think about how it would best be accomplished

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions