From 19202736d51679e3669e75e53780e6aeb4924303 Mon Sep 17 00:00:00 2001 From: Harley Acheson Date: Wed, 9 Nov 2022 09:27:59 +0100 Subject: Fix T99872: Crash Loading Embedded Fonts - 3.3 Ensure kerning cache exists when loading embedded fonts --- When loading embedded fonts from memory the font->kerning_cache is not created and so we get a crash if the font does support kerning. This was not caught because the loading of packed fonts was not actually doing anything in VSE until {523bc981cfee}. We have since consolidated `blf_font_new` and `blf_font_new_from_mem` into a single function so that they cannot get out of sync like this any more. So this fix is specific to Blender 3.3. But we can add this as a candidate for corrective release 3.2.3 Reviewed By: brecht Maniphest Tasks: T99872 Differential Revision: https://developer.blender.org/D15704 --- source/blender/blenfont/intern/blf_font.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/source/blender/blenfont/intern/blf_font.c b/source/blender/blenfont/intern/blf_font.c index 038e73cc928..07d19f307a2 100644 --- a/source/blender/blenfont/intern/blf_font.c +++ b/source/blender/blenfont/intern/blf_font.c @@ -1356,13 +1356,24 @@ FontBLF *blf_font_new_from_mem(const char *name, const unsigned char *mem, int m return NULL; } + font->name = BLI_strdup(name); + font->filepath = NULL; + blf_font_fill(font); + if (FT_HAS_MULTIPLE_MASTERS(font->face)) { FT_Get_MM_Var(font->face, &(font->variations)); } - font->name = BLI_strdup(name); - font->filepath = NULL; - blf_font_fill(font); + if (FT_HAS_KERNING(font->face)) { + /* Create kerning cache table and fill with value indicating "unset". */ + font->kerning_cache = MEM_mallocN(sizeof(KerningCacheBLF), __func__); + for (uint i = 0; i < KERNING_CACHE_TABLE_SIZE; i++) { + for (uint j = 0; j < KERNING_CACHE_TABLE_SIZE; j++) { + font->kerning_cache->ascii_table[i][j] = KERNING_ENTRY_UNSET; + } + } + } + return font; } -- cgit v1.2.3