Fix panic when drawing empty image in iced_tiny_skia

This commit is contained in:
Brock Szuszczewicz 2025-06-11 18:39:30 -06:00 committed by Héctor Ramón Jiménez
parent 4f6ccb78fe
commit dd1ff34697
No known key found for this signature in database
GPG key ID: 7CC46565708259A7
2 changed files with 7 additions and 0 deletions

View file

@ -348,6 +348,9 @@ pub enum Error {
/// Loading images is unsupported. /// Loading images is unsupported.
#[error("loading images is unsupported")] #[error("loading images is unsupported")]
Unsupported, Unsupported,
/// The image is empty.
#[error("the image is empty")]
Empty,
/// Not enough memory to allocate the image. /// Not enough memory to allocate the image.
#[error("not enough memory to allocate the image")] #[error("not enough memory to allocate the image")]
OutOfMemory, OutOfMemory,

View file

@ -106,6 +106,10 @@ impl Cache {
} }
}; };
if image.width() == 0 || image.height() == 0 {
return Err(raster::Error::Empty);
}
let mut buffer = let mut buffer =
vec![0u32; image.width() as usize * image.height() as usize]; vec![0u32; image.width() as usize * image.height() as usize];