From e8f5ab89ee0b6810649f76c6dbd15ee1105554e8 Mon Sep 17 00:00:00 2001 From: Joe Wilm Date: Sat, 14 Oct 2017 18:58:19 -0700 Subject: Fix memory leak from font resizing The source of the leak was loading up multiple copies of the FT_face even when not necessary. Fonts are now appropriately cached for FreeType when going through the `Rasterize::load_font` API. Additionally, textures in the glyph cache are now reused. The result of this is that resizing to already loaded fonts is free from a memory consumption perspective. --- src/display.rs | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'src/display.rs') diff --git a/src/display.rs b/src/display.rs index 25318f0e..eb562e8f 100644 --- a/src/display.rs +++ b/src/display.rs @@ -240,14 +240,15 @@ impl Display { return Ok((glyph_cache, cell_width as f32, cell_height as f32)); } - pub fn update_glyph_cache(&mut self, config: &Config, font_size_delta: i8) - { - let (glyph_cache, cell_width, cell_height) = - Self::new_glyph_cache(&self.window, - &mut self.renderer, config, font_size_delta).unwrap(); - self.glyph_cache = glyph_cache; - self.size_info.cell_width = cell_width; - self.size_info.cell_height = cell_height; + pub fn update_glyph_cache(&mut self, config: &Config, font_size_delta: i8) { + let cache = &mut self.glyph_cache; + self.renderer.with_loader(|mut api| { + let _ = cache.update_font_size(config.font(), font_size_delta, &mut api); + }); + + let metrics = cache.font_metrics(); + self.size_info.cell_width = (metrics.average_advance + config.font().offset().x as f64) as f32; + self.size_info.cell_height = (metrics.line_height + config.font().offset().y as f64) as f32; } #[inline] -- cgit v1.2.3-54-g00ecf