Better error message when index does not exist in texture atlas (#8396)

# Objective

- Fixes https://github.com/bevyengine/bevy/issues/8210

## Changelog

- Improve error message when `TextureAtlasSprite::index` does not exist
in texture atlas
This commit is contained in:
Mike 2023-04-17 09:10:58 -07:00 committed by GitHub
parent b03b7b557e
commit defc653528
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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,