1
1
mirror of https://github.com/wez/wezterm.git synced 2024-12-25 14:22:37 +03:00

avoid incomplete paints if loading a glyph fails

This addresses the render artifacts aspect of https://github.com/wez/wezterm/issues/671

For whatever reason, some font(s) cannot be loaded on that system
and that results in the paint routine erroring out.

This commit avoids the error by substituting a blank glyph
instead of the glyph that failed to load.

refs: https://github.com/wez/wezterm/issues/671
This commit is contained in:
Wez Furlong 2021-04-10 00:16:14 -07:00
parent 02e58d904d
commit b825f86380

View File

@ -8,7 +8,6 @@ use ::window::glium;
use ::window::glium::backend::Context as GliumContext;
use ::window::glium::texture::SrgbTexture2d;
use ::window::{Point, Rect};
use anyhow::{anyhow, Context};
use config::{configuration, AllowSquareGlyphOverflow, TextStyle};
use euclid::num::Zero;
use lru::LruCache;
@ -410,7 +409,26 @@ impl<T: Texture2d> GlyphCache<T> {
let glyph = self
.load_glyph(info, style, followed_by_space)
.with_context(|| anyhow!("load_glyph {:?} {:?}", info, style))?;
.unwrap_or_else(|err| {
// Don't allow glyph loading errors to propagate, as
// that will result in incomplete window painting.
// Log the error and substitute instead.
log::error!(
"load_glyph failed; using blank instead. Error: {:#}. {:?} {:?}",
err,
info,
style
);
Rc::new(CachedGlyph {
has_color: false,
texture: None,
x_offset: PixelLength::zero(),
y_offset: PixelLength::zero(),
bearing_x: PixelLength::zero(),
bearing_y: PixelLength::zero(),
scale: 1.0,
})
});
self.glyph_cache.insert(key.to_owned(), Rc::clone(&glyph));
Ok(glyph)
}