diff options
-rw-r--r-- | CHANGELOG.md | 1 | ||||
-rw-r--r-- | alacritty/src/renderer/mod.rs | 26 |
2 files changed, 24 insertions, 3 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index ed7783ed..9175fcad 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -69,6 +69,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Cursor color escape ignored when its color is set to inverted in the config - Fontconfig's `autohint` and `hinting` options being ignored - Ingoring of default FreeType properties +- Alacritty crashing at startup when the configured font does not exist ## 0.4.3 diff --git a/alacritty/src/renderer/mod.rs b/alacritty/src/renderer/mod.rs index bd9f4ae7..8fd6c087 100644 --- a/alacritty/src/renderer/mod.rs +++ b/alacritty/src/renderer/mod.rs @@ -10,7 +10,7 @@ use std::time::Duration; use fnv::FnvHasher; use font::{ - self, BitmapBuffer, FontDesc, FontKey, GlyphKey, Rasterize, RasterizedGlyph, Rasterizer, + self, BitmapBuffer, FontDesc, FontKey, GlyphKey, Rasterize, RasterizedGlyph, Rasterizer, Size, }; use log::{error, info}; use notify::{watcher, DebouncedEvent, RecursiveMode, Watcher}; @@ -224,7 +224,7 @@ impl GlyphCache { let regular_desc = Self::make_desc(&font.normal(), font::Slant::Normal, font::Weight::Normal); - let regular = rasterizer.load_font(®ular_desc, size)?; + let regular = Self::load_regular_font(rasterizer, ®ular_desc, size)?; // Helper to load a description if it is not the `regular_desc`. let mut load_or_regular = |desc: FontDesc| { @@ -255,6 +255,26 @@ impl GlyphCache { Ok((regular, bold, italic, bold_italic)) } + fn load_regular_font( + rasterizer: &mut Rasterizer, + description: &FontDesc, + size: Size, + ) -> Result<FontKey, font::Error> { + match rasterizer.load_font(description, size) { + Ok(font) => Ok(font), + Err(err) => { + error!("{}", err); + + let fallback_desc = Self::make_desc( + &Font::default().normal(), + font::Slant::Normal, + font::Weight::Normal, + ); + rasterizer.load_font(&fallback_desc, size) + }, + } + } + fn make_desc( desc: &config::FontDescription, slant: font::Slant, @@ -343,7 +363,7 @@ impl GlyphCache { let mut rasterizer = font::Rasterizer::new(dpr as f32, font.use_thin_strokes())?; let regular_desc = GlyphCache::make_desc(&font.normal(), font::Slant::Normal, font::Weight::Normal); - let regular = rasterizer.load_font(®ular_desc, font.size)?; + let regular = Self::load_regular_font(&mut rasterizer, ®ular_desc, font.size)?; rasterizer.get_glyph(GlyphKey { font_key: regular, c: 'm', size: font.size })?; rasterizer.metrics(regular, font.size) |