From 9b3d35623f72183f95accd543002fa1e386a0871 Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Thu, 11 Mar 2021 19:45:48 -0800 Subject: [PATCH] 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. --- wezterm-gui/src/glyphcache.rs | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/wezterm-gui/src/glyphcache.rs b/wezterm-gui/src/glyphcache.rs index 775815545..4d1caf5e3 100644 --- a/wezterm-gui/src/glyphcache.rs +++ b/wezterm-gui/src/glyphcache.rs @@ -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) -> Self { let frames = frames .into_iter() @@ -539,7 +552,12 @@ impl GlyphCache { )); } - let decoded = DecodedImage::load(image_data)?; + let decoded = + DecodedImage::load(image_data).or_else(|e| -> anyhow::Result { + 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)?;