SDL_ttf
SDL_ttf copied to clipboard
Documentation of TTF_OpenFontRW is missing key info
I came here to report that TTF_OpenFontRW fails on multiple calls with the same SDL_RWops and requesting a smaller point size than the one(s) requested before, but apparently this is well know since #108 and it's some kind of accepted behavior.
Just as reference for people who might encounter the same issue, this is what happens on multiple calls:
SDL_RWops * data;
TTF_OpenFontRW(data, 0, 20); // OK
TTF_OpenFontRW(data, 0, 22); // OK
TTF_OpenFontRW(data, 0, 22); // OK
TTF_OpenFontRW(data, 0, 18); // ERROR: Couldn't load font file
To fix that your code needs to reset the SDL_RWops with SDL_RWseek before calling TTF_OpenFontRW.
I am not sure I understand why TTF_OpenFontRW can't call SDL_RWseek(RWops, 0, RW_SEEK_SET) itself, but if that's a design choice it should be documented or people will never have a clue until they find #108 (I didn't while I was trying to figure things out) or try to call SDL_RWseek like I did (but after wasting a lot of time debugging my code and trying other random things).
It seems like for SDL_ttf 3.0 we should fix this behavior.