Open mulle-nat opened 3 years ago
I have implemented FT_Library
as a member of FONScontext
. Not sure if this solves the multithread problems completely, but it should solve the multi-context problem.
I will probably make a pull request, when this has been used a bit more.
Nanovg uses a static
FT_Library
variable, which it initializes withFT_Init_FreeType
duringfons__tt_init
which runs for each nanovg context being created. As soon as you are creating two nanovg contexts (and then destroying them), you will run into problems, asFT_Init_FreeType
andFT_Done_FreeType
don't reference count:The FreeType dox suggest replacing with
FT_New_Library
andFT_Done_Library
. These don't use atomics for reference counting though and are therefore inherently not thread safe. So it's not a perfect solution, but solves the two context problem for a single thread app.nanovg should either reference count (and skip) superflous
FT_Init_FreeType
andFT_Done_FreeType
attempts or should embed theFT_Library
static in theFONScontext
. That would create duplicate fonts though.Locking during nanovg context creation/deletion and font loading would still be needed for multi-threaded apps. I don't think locking would be a good addition to nanovg itself though.
I will have to fix this for my project, but would like to get some feedback.