Skip to content

Commit b472912

Browse files
committed
diagnostics: meaningful error when graph node has wrong number of inputs (#4924)
# Objective Currently, providing the wrong number of inputs to a render graph node triggers this assertion: ``` thread 'main' panicked at 'assertion failed: `(left == right)` left: `1`, right: `2`', /[redacted]/bevy/crates/bevy_render/src/renderer/graph_runner.rs:164:13 note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace ``` This does not provide the user any context. ## Solution Add a new `RenderGraphRunnerError` variant to handle this case. The new message looks like this: ``` ERROR bevy_render::renderer: Error running render graph: ERROR bevy_render::renderer: > node (name: 'Some("outline_pass")') has 2 input slots, but was provided 1 values ``` --- ## Changelog ### Changed `RenderGraphRunnerError` now has a new variant, `MismatchedInputCount`. ## Migration Guide Exhaustive matches on `RenderGraphRunnerError` will need to add a branch to handle the new `MismatchedInputCount` variant.
1 parent c4080c6 commit b472912

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

crates/bevy_render/src/renderer/graph_runner.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,14 @@ pub enum RenderGraphRunnerError {
4141
expected: SlotType,
4242
actual: SlotType,
4343
},
44+
#[error(
45+
"node (name: '{node_name:?}') has {slot_count} input slots, but was provided {value_count} values"
46+
)]
47+
MismatchedInputCount {
48+
node_name: Option<Cow<'static, str>>,
49+
slot_count: usize,
50+
value_count: usize,
51+
},
4452
}
4553

4654
impl RenderGraphRunner {
@@ -161,7 +169,13 @@ impl RenderGraphRunner {
161169
.map(|(_, value)| value)
162170
.collect();
163171

164-
assert_eq!(inputs.len(), node_state.input_slots.len());
172+
if inputs.len() != node_state.input_slots.len() {
173+
return Err(RenderGraphRunnerError::MismatchedInputCount {
174+
node_name: node_state.name.clone(),
175+
slot_count: node_state.input_slots.len(),
176+
value_count: inputs.len(),
177+
});
178+
}
165179

166180
let mut outputs: SmallVec<[Option<SlotValue>; 4]> =
167181
smallvec![None; node_state.output_slots.len()];

0 commit comments

Comments
 (0)