From b825f86380df0d4901ff30a4c282da883e6017ca Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Sat, 10 Apr 2021 00:16:14 -0700 Subject: [PATCH] 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 --- wezterm-gui/src/glyphcache.rs | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/wezterm-gui/src/glyphcache.rs b/wezterm-gui/src/glyphcache.rs index db11c4797..545f3df4c 100644 --- a/wezterm-gui/src/glyphcache.rs +++ b/wezterm-gui/src/glyphcache.rs @@ -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 GlyphCache { 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) }