From 7f319650635e73251527d06c72c49b95c111d646 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9ctor=20Ram=C3=B3n=20Jim=C3=A9nez?= Date: Tue, 4 Jul 2023 18:36:18 +0200 Subject: [PATCH] Fix potentially evicting glyphs in use during `try_allocate` --- src/text_atlas.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/text_atlas.rs b/src/text_atlas.rs index 6e5de01..166dbb7 100644 --- a/src/text_atlas.rs +++ b/src/text_atlas.rs @@ -84,12 +84,19 @@ impl InnerAtlas { // Try to free least recently used allocation let (mut key, mut value) = self.glyph_cache.peek_lru()?; + // Find a glyph with an actual size while value.atlas_id.is_none() { + // All sized glyphs are in use, cache is full + if self.glyphs_in_use.contains(&key) { + return None; + } + let _ = self.glyph_cache.pop_lru(); (key, value) = self.glyph_cache.peek_lru()?; } + // All sized glyphs are in use, cache is full if self.glyphs_in_use.contains(&key) { return None; }