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
@ -228,6 +228,10 @@ path = "examples/app/return_after_run.rs"
|
|||||||
name = "thread_pool_resources"
|
name = "thread_pool_resources"
|
||||||
path = "examples/app/thread_pool_resources.rs"
|
path = "examples/app/thread_pool_resources.rs"
|
||||||
|
|
||||||
|
[[example]]
|
||||||
|
name = "without_winit"
|
||||||
|
path = "examples/app/without_winit.rs"
|
||||||
|
|
||||||
# Assets
|
# Assets
|
||||||
[[example]]
|
[[example]]
|
||||||
name = "asset_loading"
|
name = "asset_loading"
|
||||||
|
@ -47,10 +47,11 @@ impl Node for MainPass3dNode {
|
|||||||
world: &World,
|
world: &World,
|
||||||
) -> Result<(), NodeRunError> {
|
) -> Result<(), NodeRunError> {
|
||||||
let view_entity = graph.get_input_entity(Self::IN_VIEW)?;
|
let view_entity = graph.get_input_entity(Self::IN_VIEW)?;
|
||||||
let (opaque_phase, alpha_mask_phase, transparent_phase, target, depth) = self
|
let (opaque_phase, alpha_mask_phase, transparent_phase, target, depth) =
|
||||||
.query
|
match self.query.get_manual(world, view_entity) {
|
||||||
.get_manual(world, view_entity)
|
Ok(query) => query,
|
||||||
.expect("view entity should exist");
|
Err(_) => return Ok(()), // No window
|
||||||
|
};
|
||||||
|
|
||||||
{
|
{
|
||||||
// Run the opaque pass, sorted front-to-back
|
// Run the opaque pass, sorted front-to-back
|
||||||
|
@ -341,7 +341,10 @@ pub fn add_clusters(
|
|||||||
cameras: Query<(Entity, &Camera), Without<Clusters>>,
|
cameras: Query<(Entity, &Camera), Without<Clusters>>,
|
||||||
) {
|
) {
|
||||||
for (entity, camera) in cameras.iter() {
|
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(
|
let clusters = Clusters::from_screen_size_and_z_slices(
|
||||||
UVec2::new(window.physical_width(), window.physical_height()),
|
UVec2::new(window.physical_width(), window.physical_height()),
|
||||||
Z_SLICES,
|
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
|
`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
|
`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
|
`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
|
## 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 New Issue
Block a user