BLF: Fix for changing the DPI storing many fonts (300+)

Each dpi value stores its own set of font sizes, so while dragging the
dpi value would collect many sizes and never free.

Also change how BLF_cache_clear works,
it was freeing memory but not the OpenGL textures.

Now just free all the cache and GL textures and let drawing allocate them again as needed.
This commit is contained in:
Campbell Barton 2014-01-17 03:04:46 +11:00
parent de28a4d4b2
commit a780e7f3f0
Notes: blender-bot 2023-02-14 11:20:23 +01:00
Referenced by commit d358f1f9e7, Fix last part of T38244: memory leak when scaling any panel
Referenced by issue #38244, memory leak when scaling any panel
2 changed files with 5 additions and 10 deletions

View File

@ -121,17 +121,9 @@ GlyphCacheBLF *blf_glyph_cache_new(FontBLF *font)
void blf_glyph_cache_clear(FontBLF *font)
{
GlyphCacheBLF *gc;
GlyphBLF *g;
int i;
for (gc = font->cache.first; gc; gc = gc->next) {
for (i = 0; i < 257; i++) {
while ((g = BLI_pophead(&gc->bucket[i]))) {
blf_glyph_free(g);
}
}
memset(gc->glyph_ascii_table, 0, sizeof(gc->glyph_ascii_table));
while ((gc = BLI_pophead(&font->cache))) {
blf_glyph_cache_free(gc);
}
}

View File

@ -111,6 +111,9 @@ static void rna_userdef_update(Main *UNUSED(bmain), Scene *UNUSED(scene), Pointe
/* also used by buffer swap switching */
static void rna_userdef_dpi_update(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *UNUSED(ptr))
{
/* font's are stored at each DPI level, without this we can easy load 100's of fonts */
BLF_cache_clear();
BKE_userdef_state();
WM_main_add_notifier(NC_WINDOW, NULL); /* full redraw */
WM_main_add_notifier(NC_SCREEN | NA_EDITED, NULL); /* refresh region sizes */