fix(app): wrap WinitWindows in Option to satisfy Bevy 0.18 param validation
`NonSend<WinitWindows>` failed system-param validation on the first few frames before `WinitWindows` was populated, panicking the Update system before any logic could run. Bevy 0.18's stricter validation panics rather than skips when a non-send resource is absent, with an error message spelling out the fix: *"wrap the parameter in `Option<T>` and handle `None` when it happens."* Wraps `winit_windows` as `Option<NonSend<WinitWindows>>` and early-returns on `None`, mirroring the same lifecycle handling already applied to `winit_windows.get_window(primary_entity)` — both fail in the same window of frames before winit's `Resumed` event fires. Repro from the user's `cargo run` log: ``` thread 'Compute Task Pool (2)' panicked at .../bevy_ecs-0.18.1/src/error/handler.rs:125:1: Encountered an error in system ...: Parameter ... failed validation: Non-send resource does not exist ``` Workspace clippy + cargo test --workspace clean, 1185 passing. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -284,11 +284,20 @@ fn apply_smart_default_window_size(
|
||||
fn set_window_icon(
|
||||
mut applied: Local<bool>,
|
||||
primary_window: Query<Entity, With<PrimaryWindow>>,
|
||||
winit_windows: NonSend<WinitWindows>,
|
||||
// `Option<NonSend<...>>` rather than `NonSend<...>` because Bevy
|
||||
// 0.18's stricter system-param validation panics on the first
|
||||
// few frames before `WinitWindows` is inserted (the resource is
|
||||
// populated after winit's `Resumed` event, which fires after
|
||||
// the first system-tick batch). The early-return below handles
|
||||
// the `None` window-wrapper case for the same lifecycle reason.
|
||||
winit_windows: Option<NonSend<WinitWindows>>,
|
||||
) {
|
||||
if *applied {
|
||||
return;
|
||||
}
|
||||
let Some(winit_windows) = winit_windows else {
|
||||
return;
|
||||
};
|
||||
let Ok(primary_entity) = primary_window.single() else {
|
||||
return;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user