Skip to content

Commit

Permalink
Better error message when index does not exist in texture atlas (bevy…
Browse files Browse the repository at this point in the history
…engine#8396)

# Objective

- Fixes bevyengine#8210

## Changelog

- Improve error message when `TextureAtlasSprite::index` does not exist
in texture atlas
  • Loading branch information
hymm authored Apr 17, 2023
1 parent b03b7b5 commit defc653
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion crates/bevy_sprite/src/render/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,18 @@ pub fn extract_sprites(
continue;
}
if let Some(texture_atlas) = texture_atlases.get(texture_atlas_handle) {
let rect = Some(texture_atlas.textures[atlas_sprite.index]);
let rect = Some(
*texture_atlas
.textures
.get(atlas_sprite.index)
.unwrap_or_else(|| {
panic!(
"Sprite index {:?} does not exist for texture atlas handle {:?}.",
atlas_sprite.index,
texture_atlas_handle.id(),
)
}),
);
extracted_sprites.sprites.push(ExtractedSprite {
entity,
color: atlas_sprite.color,
Expand Down

0 comments on commit defc653

Please sign in to comment.