From ac29bdfc86b1f9326f0ca03b2e1561635e0e2062 Mon Sep 17 00:00:00 2001 From: Brian Reavis Date: Thu, 15 Aug 2024 11:41:01 -0700 Subject: [PATCH] Fix pass_span drop panic obscuring transparent 2d render errors (#14758) # Objective When an item in the transparent 2d phase fails to render, bevy crashes with _"PassSpanScope::end was never called"_ instead of outputting the actual error to the console. This PR fixes this so that phase errors are output to the console. It also makes bevy not crash. ``` thread '' panicked at /Users/brianreavis/Repositories/project/bevy/crates/bevy_render/src/diagnostic/mod.rs:157:9: PassSpanScope::end was never called stack backtrace: 0: rust_begin_unwind at /rustc/129f3b9964af4d4a709d1383930ade12dfe7c081/library/std/src/panicking.rs:652:5 1: core::panicking::panic_fmt at /rustc/129f3b9964af4d4a709d1383930ade12dfe7c081/library/core/src/panicking.rs:72:14 2: as core::ops::drop::Drop>::drop at /Users/brianreavis/Repositories/project/bevy/crates/bevy_render/src/diagnostic/mod.rs:157:9 3: core::ptr::drop_in_place>,bevy_render::render_phase::draw_state::TrackedRenderPass>> at /rustc/129f3b9964af4d4a709d1383930ade12dfe7c081/library/core/src/ptr/mod.rs:514:1 4: ::run at /Users/brianreavis/Repositories/project/bevy/crates/bevy_core_pipeline/src/core_2d/main_transparent_pass_2d_node.rs:75:9 5: as bevy_render::render_graph::node::Node>::run at /Users/brianreavis/Repositories/project/bevy/crates/bevy_render/src/render_graph/node.rs:406:9 6: bevy_render::renderer::graph_runner::RenderGraphRunner::run_graph at /Users/brianreavis/Repositories/project/bevy/crates/bevy_render/src/renderer/graph_runner.rs:226:21 7: bevy_render::renderer::graph_runner::RenderGraphRunner::run_graph at /Users/brianreavis/Repositories/project/bevy/crates/bevy_render/src/renderer/graph_runner.rs:233:21 8: bevy_render::renderer::graph_runner::RenderGraphRunner::run at /Users/brianreavis/Repositories/project/bevy/crates/bevy_render/src/renderer/graph_runner.rs:81:9 9: bevy_render::renderer::render_system at /Users/brianreavis/Repositories/project/bevy/crates/bevy_render/src/renderer/mod.rs:40:15 10: core::ops::function::FnMut::call_mut at /rustc/129f3b9964af4d4a709d1383930ade12dfe7c081/library/core/src/ops/function.rs:166:5 11: core::ops::function::impls:: for &mut F>::call_mut at /rustc/129f3b9964af4d4a709d1383930ade12dfe7c081/library/core/src/ops/function.rs:294:13 12: Out>>::run::call_inner at /Users/brianreavis/Repositories/project/bevy/crates/bevy_ecs/src/system/exclusive_function_system.rs:229:21 13: Out>>::run at /Users/brianreavis/Repositories/project/bevy/crates/bevy_ecs/src/system/exclusive_function_system.rs:232:17 14: as bevy_ecs::system::system::System>::run::{{closure}} at /Users/brianreavis/Repositories/project/bevy/crates/bevy_ecs/src/system/exclusive_function_system.rs:124:23 15: bevy_ecs::world::World::last_change_tick_scope at /Users/brianreavis/Repositories/project/bevy/crates/bevy_ecs/src/world/mod.rs:2383:9 16: as bevy_ecs::system::system::System>::run at /Users/brianreavis/Repositories/project/bevy/crates/bevy_ecs/src/system/exclusive_function_system.rs:116:9 note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace. ``` ## Solution Matched the behavior of the other render phases ([like here](https://github.com/bevyengine/bevy/blob/9ca5540b759c9e2571147c26b484029d93976be8/crates/bevy_core_pipeline/src/core_3d/main_opaque_pass_3d_node.rs#L98-L101)) --- .../src/core_2d/main_transparent_pass_2d_node.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/crates/bevy_core_pipeline/src/core_2d/main_transparent_pass_2d_node.rs b/crates/bevy_core_pipeline/src/core_2d/main_transparent_pass_2d_node.rs index 2c82ccc800..e365be9547 100644 --- a/crates/bevy_core_pipeline/src/core_2d/main_transparent_pass_2d_node.rs +++ b/crates/bevy_core_pipeline/src/core_2d/main_transparent_pass_2d_node.rs @@ -9,6 +9,7 @@ use bevy_render::{ renderer::RenderContext, view::{ViewDepthTexture, ViewTarget}, }; +use bevy_utils::tracing::error; #[cfg(feature = "trace")] use bevy_utils::tracing::info_span; @@ -68,7 +69,12 @@ impl ViewNode for MainTransparentPass2dNode { } if !transparent_phase.items.is_empty() { - transparent_phase.render(&mut render_pass, world, view_entity)?; + #[cfg(feature = "trace")] + let _transparent_main_pass_2d_span = + info_span!("transparent_main_pass_2d").entered(); + if let Err(err) = transparent_phase.render(&mut render_pass, world, view_entity) { + error!("Error encountered while rendering the transparent 2D phase {err:?}"); + } } pass_span.end(&mut render_pass);