Skip to content

[Merged by Bors] - Fix crash with disabled winit #3330

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
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
4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,10 @@ path = "examples/app/return_after_run.rs"
name = "thread_pool_resources"
path = "examples/app/thread_pool_resources.rs"

[[example]]
name = "without_winit"
path = "examples/app/without_winit.rs"

# Assets
[[example]]
name = "asset_loading"
Expand Down
9 changes: 5 additions & 4 deletions crates/bevy_core_pipeline/src/main_pass_3d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,11 @@ impl Node for MainPass3dNode {
world: &World,
) -> Result<(), NodeRunError> {
let view_entity = graph.get_input_entity(Self::IN_VIEW)?;
let (opaque_phase, alpha_mask_phase, transparent_phase, target, depth) = self
.query
.get_manual(world, view_entity)
.expect("view entity should exist");
let (opaque_phase, alpha_mask_phase, transparent_phase, target, depth) =
match self.query.get_manual(world, view_entity) {
Ok(query) => query,
Err(_) => return Ok(()), // No window
};

{
// Run the opaque pass, sorted front-to-back
Expand Down
5 changes: 4 additions & 1 deletion crates/bevy_pbr/src/light.rs
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,10 @@ pub fn add_clusters(
cameras: Query<(Entity, &Camera), Without<Clusters>>,
) {
for (entity, camera) in cameras.iter() {
let window = windows.get(camera.window).unwrap();
let window = match windows.get(camera.window) {
Some(window) => window,
None => continue,
};
let clusters = Clusters::from_screen_size_and_z_slices(
UVec2::new(window.physical_width(), window.physical_height()),
Z_SLICES,
Expand Down
1 change: 1 addition & 0 deletions examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ Example | File | Description
`plugin_group` | [`app/plugin_group.rs`](./app/plugin_group.rs) | Demonstrates the creation and registration of a custom plugin group
`return_after_run` | [`app/return_after_run.rs`](./app/return_after_run.rs) | Show how to return to main after the Bevy app has exited
`thread_pool_resources` | [`app/thread_pool_resources.rs`](./app/thread_pool_resources.rs) | Creates and customizes the internal thread pool
`without_winit` | [`app/without_winit.rs`](./app/without_winit.rs) | Create an application without winit (runs single time, no event loop)

## Assets

Expand Down
13 changes: 13 additions & 0 deletions examples/app/without_winit.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
use bevy::prelude::*;
use bevy::winit::WinitPlugin;

fn main() {
App::new()
.add_plugins_with(DefaultPlugins, |group| group.disable::<WinitPlugin>())
.add_system(setup_system)
.run();
}

fn setup_system(mut commands: Commands) {
commands.spawn_bundle(PerspectiveCameraBundle::default());
}