I was having a problem in which TTF_OpenFont was sometimes returning NULL with parameters that had previously worked. I finally debugged into the code to see what was going on. In a couple of steps, it calls TTF_OpenFontIndexDPI, which is as follows:
TTF_Font* TTF_OpenFontIndexDPI( const char *file, int ptsize, long index, unsigned int hdpi, unsigned int vdpi )
{
SDL_RWops *rw = SDL_RWFromFile(file, "rb");
if ( rw == NULL ) {
return NULL;
}
return TTF_OpenFontIndexDPIRW(rw, 1, ptsize, index, hdpi, vdpi);
}
I think I see a problem here. This function calls SDL_RWFromFile which creates an open file descriptor which it never closes. Do this often enough, SDL_RWFromFile starts returning NULL. Sure looks to me like a failure to close a resource, and eventually the system runs out of file descriptors. Please tell me I’m wrong, but this sure is what it looks like.
I solved my problem for the moment by setting up a caching scheme so that I will never call TTF_OpenFont with the same parameters twice. But this seems a bit unclean.