1
1
mirror of https://github.com/wez/wezterm.git synced 2024-11-23 15:04:36 +03:00

handle image decoding errors and return a placeholder

https://i.giphy.com/media/3owvKqP4VSydZE4pvq/200w.gif cannot
be decoded as an animated gif due to this error: `No end code in lzw stream`

Ensure that we don't completely fail to process the render phase
as a result.
This commit is contained in:
Wez Furlong 2021-03-11 19:45:48 -08:00
parent b8390b3f7a
commit 9b3d35623f

View File

@ -228,6 +228,19 @@ struct DecodedImage {
}
impl DecodedImage {
fn placeholder() -> Self {
let image = ::window::bitmaps::Image::new(1, 1);
let frame = ImageFrame {
duration: Duration::default(),
image,
};
Self {
frame_start: Instant::now(),
current_frame: 1,
frames: vec![frame],
}
}
fn with_frames(frames: Vec<image::Frame>) -> Self {
let frames = frames
.into_iter()
@ -539,7 +552,12 @@ impl<T: Texture2d> GlyphCache<T> {
));
}
let decoded = DecodedImage::load(image_data)?;
let decoded =
DecodedImage::load(image_data).or_else(|e| -> anyhow::Result<DecodedImage> {
log::error!("Failed to decode image: {:#}", e);
// Use a placeholder instead
Ok(DecodedImage::placeholder())
})?;
let sprite = self
.atlas
.allocate_with_padding(&decoded.frames[0].image, padding)?;