grimfang4 / SDL_FontCache

A generic font caching C library with loading and rendering support for SDL.
MIT License
305 stars 66 forks source link

Fix crashing when SDL_HINT_RENDER_SCALE_QUALITY has no previous value #43

Closed thrimbor closed 4 years ago

thrimbor commented 4 years ago

It's possible for hints in SDL to have no value, and if that's the case, SDL_GetHint() will return NULL. FC_UploadGlyphCache didn't handle this case and instead passed the NULL to snprintf() which made it crash on my target system.

I modified the function to check the obtained pointer first, and only execute the snprintf (and the later hint-resetting) if that pointer isn't NULL. This fixed the crash for me. I modified the function to check the obtained pointer first, and if it is NULL, it gets set to the string constant "nearest" instead. This fixed the crash for me.

dracc commented 4 years ago

I'm thinking that setting old-filter-mode to "nearest" if the call to SDL_GetHint returned NULL might be a cleaner solution? Would only require one if-case and still complies to SDL documentation.

thrimbor commented 4 years ago

Yeah, that's probably better. I changed it now.