From 09a3d8abe062984479bf0e99fcc1508bb722baf6 Mon Sep 17 00:00:00 2001 From: Daniel McNab <36049421+DJMcNab@users.noreply.github.com> Date: Mon, 30 May 2022 15:32:48 +0000 Subject: [PATCH] Allow minimising in 2d (#4527) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit # Objective - We can't minimise if there's a 2d camera because ??? there legally must be a 2d target. - Fixes https://github.com/bevyengine/bevy/issues/4526 - Fixes https://github.com/bevyengine/bevy/issues/4856 ## Solution - Make it not crash in those cases, just do nothing - Seems to work ¯\\_(ツ)_/¯ - See also the companion commit in https://github.com/bevyengine/bevy/pull/3597 - 503c24717321bb2bb2681b358020ad1bcbef510e Co-authored-by: Asteria --- crates/bevy_core_pipeline/src/main_pass_2d.rs | 9 +++++---- crates/bevy_ui/src/render/render_pass.rs | 11 ++++++----- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/crates/bevy_core_pipeline/src/main_pass_2d.rs b/crates/bevy_core_pipeline/src/main_pass_2d.rs index 563edd3a9f527..6fc8537a158bf 100644 --- a/crates/bevy_core_pipeline/src/main_pass_2d.rs +++ b/crates/bevy_core_pipeline/src/main_pass_2d.rs @@ -39,10 +39,11 @@ impl Node for MainPass2dNode { world: &World, ) -> Result<(), NodeRunError> { let view_entity = graph.get_input_entity(Self::IN_VIEW)?; - let (transparent_phase, target) = self - .query - .get_manual(world, view_entity) - .expect("view entity should exist"); + // If there is no view entity, do not try to process the render phase for the view + let (transparent_phase, target) = match self.query.get_manual(world, view_entity) { + Ok(it) => it, + _ => return Ok(()), + }; if transparent_phase.items.is_empty() { return Ok(()); diff --git a/crates/bevy_ui/src/render/render_pass.rs b/crates/bevy_ui/src/render/render_pass.rs index ccaa880e14a7e..90d80296027e8 100644 --- a/crates/bevy_ui/src/render/render_pass.rs +++ b/crates/bevy_ui/src/render/render_pass.rs @@ -66,15 +66,16 @@ impl Node for UiPassNode { world: &World, ) -> Result<(), NodeRunError> { let view_entity = graph.get_input_entity(Self::IN_VIEW)?; - let (transparent_phase, target) = self - .query - .get_manual(world, view_entity) - .expect("view entity should exist"); + + // If there is no view entity, do not try to process the render phase for the view + let (transparent_phase, target) = match self.query.get_manual(world, view_entity) { + Ok(it) => it, + _ => return Ok(()), + }; if transparent_phase.items.is_empty() { return Ok(()); } - let pass_descriptor = RenderPassDescriptor { label: Some("ui_pass"), color_attachments: &[RenderPassColorAttachment {