From 2f8499415b00a34a528a66e94d1c56cd07f9b859 Mon Sep 17 00:00:00 2001 From: Bastien Montagne Date: Tue, 7 Nov 2023 11:04:03 +0100 Subject: [PATCH] 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. --- source/blender/sequencer/intern/effects.cc | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/source/blender/sequencer/intern/effects.cc b/source/blender/sequencer/intern/effects.cc index b96e116d80b..b2da0f6f405 100644 --- a/source/blender/sequencer/intern/effects.cc +++ b/source/blender/sequencer/intern/effects.cc @@ -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); + } } }