Skip to content

Commit 1c573de

Browse files
committed
Fix panic in multiple_windows example (#1737)
Fixes #1736 There seemed to be an obvious transcription error where `setup_pipeline` was being called during `on_update` of `AppState::CreateWindow` instead of `AppState::Setup`. However, the example still panicked after fixing that. I'm not sure if there's some intended or unintended change in event processing during state transitions or something, but this PR make the example work again. Cleaned up an unused `Stage` label while I was in there. Please feel free to close this in favor of another approach.
1 parent 248ec1e commit 1c573de

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

examples/window/multiple_windows.rs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,21 +21,17 @@ fn main() {
2121
.add_system_set(
2222
SystemSet::on_update(AppState::CreateWindow).with_system(setup_window.system()),
2323
)
24-
.add_system_set(
25-
SystemSet::on_enter(AppState::CreateWindow).with_system(setup_pipeline.system()),
26-
)
24+
.add_system_set(SystemSet::on_update(AppState::Setup).with_system(setup_pipeline.system()))
2725
.run();
2826
}
2927

30-
#[derive(Debug, Hash, PartialEq, Eq, Clone, StageLabel)]
31-
pub struct Stage;
32-
3328
// NOTE: this "state based" approach to multiple windows is a short term workaround.
3429
// Future Bevy releases shouldn't require such a strict order of operations.
3530
#[derive(Clone, Eq, PartialEq)]
3631
enum AppState {
3732
CreateWindow,
3833
Setup,
34+
Done,
3935
}
4036

4137
fn setup_window(
@@ -66,13 +62,18 @@ fn setup_pipeline(
6662
mut render_graph: ResMut<RenderGraph>,
6763
asset_server: Res<AssetServer>,
6864
msaa: Res<Msaa>,
65+
mut app_state: ResMut<State<AppState>>,
6966
) {
7067
// get the non-default window id
7168
let window_id = windows
7269
.iter()
7370
.find(|w| w.id() != WindowId::default())
74-
.map(|w| w.id())
75-
.unwrap();
71+
.map(|w| w.id());
72+
73+
let window_id = match window_id {
74+
Some(window_id) => window_id,
75+
None => return,
76+
};
7677

7778
// here we setup our render graph to draw our second camera to the new window's swap chain
7879

@@ -205,4 +206,6 @@ fn setup_pipeline(
205206
transform: Transform::from_xyz(6.0, 0.0, 0.0).looking_at(Vec3::ZERO, Vec3::Y),
206207
..Default::default()
207208
});
209+
210+
app_state.set_next(AppState::Done).unwrap();
208211
}

0 commit comments

Comments
 (0)