Fix #113044: Reset Fonts When Loading New Files #113104

Merged
Harley Acheson merged 1 commits from Harley/blender:Fix113044 into blender-v4.0-release 2023-10-03 01:21:10 +02:00
3 changed files with 27 additions and 0 deletions

View File

@ -34,6 +34,12 @@ struct rcti;
int BLF_init(void);
void BLF_exit(void);
/**
* Close any user-loaded fonts that are not used by the Interface. Call when
* loading new blend files so that the old fonts are not still taking resources.
*/
void BLF_reset_fonts(void);
void BLF_cache_clear(void);
/**

View File

@ -81,6 +81,21 @@ void BLF_exit()
blf_font_exit();
}
void BLF_reset_fonts()
{
const int def_font = BLF_default();
for (int i = 0; i < BLF_MAX_FONT; i++) {
FontBLF *font = global_font[i];
if (font && !ELEM(i, def_font, blf_mono_font, blf_mono_font_render) &&
!(font->flags & BLF_DEFAULT))
{
/* Remove fonts that are not used in the UI or part of the stack. */
blf_font_free(font);
global_font[i] = nullptr;
}
}
}
void BLF_cache_clear()
{
for (int i = 0; i < BLF_MAX_FONT; i++) {

View File

@ -1029,6 +1029,9 @@ bool WM_file_read(bContext *C, const char *filepath, ReportList *reports)
if (bfd != nullptr) {
wm_file_read_pre(use_data, use_userdef);
/* Close any user-loaded fonts. */
BLF_reset_fonts();
/* Put WM into a stable state for post-readfile processes (kill jobs, removes event handlers,
* message bus, and so on). */
BlendFileReadWMSetupData *wm_setup_data = wm_file_read_setup_wm_init(C, bmain, false);
@ -2567,6 +2570,9 @@ static int wm_homefile_read_exec(bContext *C, wmOperator *op)
}
}
/* Close any user-loaded fonts. */
BLF_reset_fonts();
char app_template_buf[sizeof(U.app_template)];
const char *app_template;
PropertyRNA *prop_app_template = RNA_struct_find_property(op->ptr, "app_template");