Unable to create the primary window manually after updating to v0.13
- Dominant language
- Rust
- Stars
- 48.2k
- Forks
- 4.8k
- Avg merge
- 3d 22h
- Merged PRs (30d)
- 161
Description
## Bevy version
v0.13.0
## Relevant system information
- OS
```
Linux 6.5.3-arch1- x86_64 GNU/Linux
```
- Rust
```
cargo 1.78.0-nightly (194a60b29 2024-02-21)
```
- Adapter
```
AdapterInfo { name: "Intel(R) Graphics (ADL GT2)", vendor: 32902, device: 18086, device_type: IntegratedGpu, driver: "Intel open-source Mesa driver", driver_info: "Mesa 23.1.7-arch1.1", backend: Vulkan }
```
## What you did
```rust
use bevy::{
prelude::*,
window::PrimaryWindow,
};
fn main() {
let mut app = App::new();
let window_plugin = WindowPlugin { primary_window: None, ..Default::default() };
app.add_plugins(DefaultPlugins.set(window_plugin).build());
app.world.spawn((
PrimaryWindow,
Window { title: "Primary window.".to_owned(), ..Default::default() },
));
app.run();
}
```
## What went wrong
- What were you expecting?
Primary window to appear like it does in v0.12
- What actually happened?
Primary window never appears
## Additional information
It's interesting because if I didn't specify `None` as primary window in the `WindowPlugin`, the second window appears. So this works:
```rust
use bevy::prelude::*;
fn main() {
let mut app = App::new();
let window_plugin = WindowPlugin {
primary_window: Some(Window { title: "Primary window.".to_owned(), ..Default::default() }),
..Default::default()
};
app.add_plugins(DefaultPlugins.set(window_plugin).build());
app.world.spawn((Window { title: "Secondary window.".to_owned(), ..Default::default() },));
app.run();
}
```
I've tried to debug it a bit and here is an interesting observation:
- Windows are created using [create_windows](https://github.com/bevyengine/bevy/blob/fc0aa4f7b1abcf6870dc6c85f234558c40de24f7/crates/bevy_winit/src/system.rs#L34) system
- Which is either called (in my platform) while [build](https://github.com/bevyengine/bevy/blob/fc0aa4f7b1abcf6870dc6c85f234558c40de24f7/crates/bevy_winit/src/lib.rs#L150C13-L150C27)ing `WinitPlugin`
- Or in the [run_app_update_if_should](https://github.com/bevyengine/bevy/blob/fc0aa4f7b1abcf6870dc6c85f234558c40de24f7/crates/bevy_winit/src/lib.rs#L697C4-L697C28) system
- Since I'm adding the window after adding `WinitPlugin`, I need `run_app_update_if_should` to be run
- (btw, I can't disable `WinitPlugin` and then add it later after I manually add my window as in the real use case I need the `EventLoop` resource, which is added by `WinitPlugin`)
- `run_app_update_if_should` system is ran from two different locations:
- On `WindowEvent::RedrawRequested` event ([here](https://github.com/bevyengine/bevy/blob/fc0aa4f7b1abcf6870dc6c85f234558c40de24f7/crates/bevy_winit/src/lib.rs#L607)), which I'm not sure how it's triggered
- Or on `Event::AboutToWait` event ([here](https://github.com/bevyengine/bevy/blob/fc0aa4f7b1abcf6870dc6c85f234558c40de24f7/crates/bevy_winit/src/lib.rs#L383)), if `should_update` is true
- In the debugger, these are the events that I'm getting:
- Event::NewEvents(StartCause::Init) (this is pretty expected)
- Event::Resumed (not sure why this is but the important thing is it sets `runner_state.redraw_requested = true`)
- (now this is the perfect time because if the next event is `Event::AboutToWait`, `should_update` will be set to `true` due to `runner_state.redraw_requested = true` in the previous event, but it's never received, instead:)
- Event::DeviceEvent { event: DeviceEvent::Motion { ... }, ... }
- Event::DeviceEvent { event: DeviceEvent::MouseWheel { ... }, ... }
- Event::DeviceEvent { event: DeviceEvent::Motion { ... }, ... }
- Event::DeviceEvent { event: DeviceEvent::MouseWheel { ... }, ... }
- ...
- (this goes on, it might be due to debugger, but the fact remains, window never appears, with or without the debugger...)
The real use case is https://github.com/umut-sahin/bevy-persistent-windows/, which was working on v0.12, but doesn't work on v0.13, hence the issue. I'm also open to alternative ways to achieve what this library is trying to achieve.
Thanks for the amazing engine, let me know if I can provide any other information :raised_hands:
Contributor guide
Assessment
This issue has not been assessed yet.