ALLEGRO_FILE *memfile = al_open_memfile(buffer, file_size, "rb"); std::string fn = file_name; fn.append(file_type); f = al_load_ttf_font_f(memfile, fn.c_str(), size, flags); //al_fclose(memfile);
Note that I have commented out al_fclose(memfile);
This way it doesn't crash. However, if I close the memfile, it will crash as soon as the game has to draw some text using the loaded font.
http://www.allegro.cc/manual/5/al_load_ttf_font_f
says:
Note: The file handle is owned by the returned ALLEGRO_FONT object and must not be freed by the caller, as FreeType expects to be able to read from it at a later time.
To my understanding, the note says that I am not supposed to free buffer.
So do I get it right - I must not al_fclose the memfile and I must not al_free the buffer?
So do I get it right - I must not al_fclose the memfile and I must not al_free the buffer?
Right.
Of course, you must still free the memory after you destroy the font. (Check the source to see if it closes the file for you.)
Thanks. Do I have to al_fclose the memfile too after having freed the memory?
you want to close it before freeing the memory I think.