mirror of
https://github.com/bevyengine/bevy
synced 2024-11-10 07:04:33 +00:00
Fix crash with disabled winit (#3330)
# Objective This PR fixes a crash when winit is enabled when there is a camera in the world. Part of #3155 ## Solution In this PR, I removed two unwraps and added an example for regression testing.
This commit is contained in:
parent
c061ec33c8
commit
70c9165886
5 changed files with 27 additions and 5 deletions
|
@ -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"
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -341,7 +341,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,
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
13
examples/app/without_winit.rs
Normal file
13
examples/app/without_winit.rs
Normal file
|
@ -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());
|
||||
}
|
Loading…
Reference in a new issue