Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » al_load_ttf_font_f crash

This thread is locked; no one can reply to it. rss feed Print
al_load_ttf_font_f crash
Hyena_
Member #8,852
July 2007
avatar

    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?

Matthew Leverton
Supreme Loser
January 1999
avatar

Hyena_ said:

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.)

Hyena_
Member #8,852
July 2007
avatar

Thanks. Do I have to al_fclose the memfile too after having freed the memory?

Thomas Fjellstrom
Member #476
June 2000
avatar

you want to close it before freeing the memory I think.

--
Thomas Fjellstrom - [website] - [email] - [Allegro Wiki] - [Allegro TODO]
"If you can't think of a better solution, don't try to make a better solution." -- weapon_S
"The less evidence we have for what we believe is certain, the more violently we defend beliefs against those who don't agree" -- https://twitter.com/neiltyson/status/592870205409353730

Go to: