Open mikaib opened 3 months ago
I updated nanovg and fontstash. There are some more functions using the fontindex now. But it still is suboptimal since the stash doesnt really support releasing the fonts and doesnt allow for a proper lifecycle. Fontstash is also super ugly so im pondering a rewrite atm.
Description There is a problem with NanoVG where certain fonts are unable to be unloaded. Let's say I load a font called font1, then load another font called font2. At this point
stash->nfonts
will be 2 If I now unload font1stash->nfonts
will be 1 again. This means that font2 cannot be unloaded as there is a check in place (idx >= stash->nfonts
) I've confirmed this is the problem by trying to unload them in reverse order (font2, font1
instead offont1, font2
) which made the problems disappear.To Reproduce Steps to reproduce the behavior:
Expected behavior When you attempt step 3 of the reproduction steps, you should be able to unload the font and the function should return true.
Proposed solution Instead of checking if
idx >= stash->nfonts
is true, possibly check if the font at the specified index is a nullptr, with perhaps some additional sanity-checks likeidx >= FONS_INIT_FONTS
Additional details Outside of the code added to this fork to free the font, there is also a problem with finding fonts. As it uses a for-loop for finding the fonts, where sometimes a font might be outside of the range of the font