Fix extensionless image loading panic (#13005)

Remake of #12938 targeting main
This commit is contained in:
Victor 2024-04-17 17:13:33 +02:00 committed by GitHub
parent cab1c5702a
commit 11afe16079
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -91,13 +91,14 @@ impl AssetLoader for ImageLoader {
settings: &'a ImageLoaderSettings,
load_context: &'a mut LoadContext<'_>,
) -> Result<Image, Self::Error> {
// use the file extension for the image type
let ext = load_context.path().extension().unwrap().to_str().unwrap();
let mut bytes = Vec::new();
reader.read_to_end(&mut bytes).await?;
let image_type = match settings.format {
ImageFormatSetting::FromExtension => ImageType::Extension(ext),
ImageFormatSetting::FromExtension => {
// use the file extension for the image type
let ext = load_context.path().extension().unwrap().to_str().unwrap();
ImageType::Extension(ext)
}
ImageFormatSetting::Format(format) => ImageType::Format(format),
};
Ok(Image::from_buffer(