Text strip data were freed each time during depsgraph update and BLF_load() had to run always before rendering.
BLF_load() was executed from non-main thread by render job, which shouldn't happen.
This patch loads fonts once and keeps them in font table until they are removed by user or file is closed.
There were attempts to load font on both original and COW scene, and various oddities in user counting.
I tried to rectify those - I don't want to change usercount during depsgraph update or during undo. I don't know how to check if I am freeing data because of undo properly.
I used hack to get around this problem:
// XXX This is only way I can tell if I should actually touch font usercount. do_user = (scene->ed->cache) != NULL; sh.free(seq, do_user);
Looking back at https://developer.blender.org/D3621?id=12926#inline-35582 where this scenario was discussed.
Proposed solution was to use BLF_load_unique. Technically I would need to account for 3 fonts per strip - for preview, prefetch and render. That is quite limiting.
I would probably want to clarify what is thread unsafe here:
- VFont is used only because there is existing UI template for it. Only usage in code is reading VFont->name and usercount handling.
- I am not quite sure if it is ok to use it like this without any further checks. Seems quite safe to me.
- Unloading font may (likely) cause crash during rendering and prefetching.
- Probably not hard to fix, Perhaps we could use FontBLF->glyph_cache_mutex here. But this is different problem.
- I am not sure if using non-unique font is problematic either, because sequencer rendering is locked by mutex. But ok, there may be conflict between VSE and another code using same font.
- If this is valid problem, perhaps I could replace global font table with ghash? or perhaps have sequencer font cache + interface to use fonts from local caches?