Skip to content

Commit

Permalink
Fix panic when using image in UiMaterial (#10591)
Browse files Browse the repository at this point in the history
# Objective

- Fix the panic on using Images in UiMaterials due to assets not being
loaded.
- Fixes #10513 

## Solution

- add `let else` statement that `return`s or `continue`s instead of
unwrapping, causing a panic.
  • Loading branch information
MarkusTheOrt authored Nov 16, 2023
1 parent c7f5cec commit efc7dc0
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions crates/bevy_ui/src/render/ui_material_pipeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -298,10 +298,9 @@ impl<P: PhaseItem, M: UiMaterial, const I: usize> RenderCommand<P>
materials: SystemParamItem<'w, '_, Self::Param>,
pass: &mut TrackedRenderPass<'w>,
) -> RenderCommandResult {
let material = materials
.into_inner()
.get(&material_handle.material)
.unwrap();
let Some(material) = materials.into_inner().get(&material_handle.material) else {
return RenderCommandResult::Failure;
};
pass.set_bind_group(I, &material.bind_group, &[]);
RenderCommandResult::Success
}
Expand Down Expand Up @@ -732,7 +731,9 @@ pub fn queue_ui_material_nodes<M: UiMaterial>(
let draw_function = draw_functions.read().id::<DrawUiMaterial<M>>();

for (entity, extracted_uinode) in extracted_uinodes.uinodes.iter() {
let material = render_materials.get(&extracted_uinode.material).unwrap();
let Some(material) = render_materials.get(&extracted_uinode.material) else {
continue;
};
for (view, mut transparent_phase) in &mut views {
let pipeline = pipelines.specialize(
&pipeline_cache,
Expand Down

0 comments on commit efc7dc0

Please sign in to comment.