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:
parent
b8390b3f7a
commit
9b3d35623f
@ -228,6 +228,19 @@ struct DecodedImage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl 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 {
|
fn with_frames(frames: Vec<image::Frame>) -> Self {
|
||||||
let frames = frames
|
let frames = frames
|
||||||
.into_iter()
|
.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
|
let sprite = self
|
||||||
.atlas
|
.atlas
|
||||||
.allocate_with_padding(&decoded.frames[0].image, padding)?;
|
.allocate_with_padding(&decoded.frames[0].image, padding)?;
|
||||||
|
Loading…
Reference in New Issue
Block a user