Fix (studio-reported) VSE crash when Text strips use missing fonts.

BLF code is not threadsafe, yet font loading gets called over and over
by text strips when the font file is missing, including e.g. from
depsgraph evaluation code when duplicating the strip for evaluation.

WARNING: This is a quick fix for deblocking the Blender studio, proper
fix (and report) still needs to be worked on.
This commit is contained in:
Bastien Montagne 2023-11-07 11:04:03 +01:00
parent ecbb77c558
commit 2f8499415b
1 changed files with 12 additions and 3 deletions

View File

@ -3251,10 +3251,19 @@ void SEQ_effect_text_font_load(TextVars *data, const bool do_id_user)
else {
char filepath[FILE_MAX];
STRNCPY(filepath, vfont->filepath);
BLI_assert(BLI_thread_is_main());
BLI_path_abs(filepath, ID_BLEND_PATH_FROM_GLOBAL(&vfont->id));
if (BLI_thread_is_main()) {
/* FIXME: This is a band-aid fix. A proper solution has to be worked on by the VSE team.
*
* This code can be called from non-main thread, e.g. when copying sequences as part of
* depsgraph CoW copy of the evaluated scene. Just skip font loading in that case, BLF code
* is not thread-safe, and if this happens from threaded context, it almost certainly means
* that a previous atempt to load the font already failed, e.g. because font filepath is
* invalid. Propoer fix would likely be to not attempt to reload a failed-to-load font every
* time. */
BLI_path_abs(filepath, ID_BLEND_PATH_FROM_GLOBAL(&vfont->id));
data->text_blf_id = BLF_load(filepath);
data->text_blf_id = BLF_load(filepath);
}
}
}