From 7f5cd017cbb2bbeff0609c04dead27695553a903 Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Fri, 27 Aug 2021 14:53:55 +0200 Subject: [PATCH] Fix potential deadlock when using `FontCache::em_width` --- gpui/src/font_cache.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/gpui/src/font_cache.rs b/gpui/src/font_cache.rs index b1deb802fd5bb18b83023a1be71910a53a8626de..3c11b9659cb26441ab7746bac6a6f306fdbcef42 100644 --- a/gpui/src/font_cache.rs +++ b/gpui/src/font_cache.rs @@ -147,9 +147,13 @@ impl FontCache { } pub fn em_width(&self, font_id: FontId, font_size: f32) -> f32 { - let state = self.0.read(); - let glyph_id = state.fonts.glyph_for_char(font_id, 'm').unwrap(); - let bounds = state.fonts.typographic_bounds(font_id, glyph_id).unwrap(); + let glyph_id; + let bounds; + { + let state = self.0.read(); + glyph_id = state.fonts.glyph_for_char(font_id, 'm').unwrap(); + bounds = state.fonts.typographic_bounds(font_id, glyph_id).unwrap(); + } self.scale_metric(bounds.width(), font_id, font_size) }