Allegro.cc - Online Community

Allegro.cc Forums » Allegro Development » TTF reinitialization bug after al_shutdown_allegro

This thread is locked; no one can reply to it. rss feed Print
TTF reinitialization bug after al_shutdown_allegro
Mark Oates
Member #1,146
March 2001
avatar

When re-initializing the TTF addon after al_shutdown_allegro, it will not be properly initialized unless a call to al_uninstall_ttf_addon is provided after al_shutdown_allegro.

Here's a minimal program with two commented lines of code that will show the different results:

#SelectExpand
1#include <allegro5/allegro.h> 2 3#include <allegro5/allegro_font.h> 4#include <allegro5/allegro_ttf.h> 5#include <string> 6#include <iostream> 7 8int main(int argc, char **argv) 9{ 10 std::string full_font_path = "/Users/markoates/Repos/allegro_flare/bin/data/fonts/DroidSans.ttf"; 11 12 // ---- 13 14 al_init(); 15 al_init_font_addon(); 16 al_init_ttf_addon(); 17 18 ALLEGRO_FONT *font = al_load_font(full_font_path.c_str(), 20, 0); 19 20 int first_load_width = al_get_text_width(font, "W"); 21 22 //al_shutdown_ttf_addon(); // <-- this results in a segfault 23 al_uninstall_system(); 24 //al_shutdown_ttf_addon(); // <-- this is required for al_init_ttf_addon() to be re-initialized below, otherwise 25 // the subsequent al_get_text_width will return 0 26 27 // ---- 28 29 al_init(); 30 al_init_font_addon(); 31 al_init_ttf_addon(); 32 33 ALLEGRO_FONT *second_font = al_load_font(full_font_path.c_str(), 20, 0); 34 35 int second_load_width = al_get_text_width(second_font, "W"); 36 37 al_uninstall_system(); 38 39 // ---- 40 41 if (first_load_width == second_load_width) 42 std::cout << "PASS (" << first_load_width << " != " << second_load_width << ")" << std::endl; 43 else 44 std::cout << "FAIL (" << first_load_width << " != " << second_load_width << ")" << std::endl; 45 46 return 0; 47}

Didn't have time to go into causes, but it appeared as a flakey test during several test runs.

So question is, should al_shutdown_allegro also shutdown and uninstall all the addons? That's my expectation. If it's not, which ones would I need to shutdown in order to ensure a clean slate?

Elias
Member #358
May 2000

I think that's a bug, for example if you compare the font addon:

https://github.com/liballeg/allegro5/blob/master/addons/font/font.c#L381

It registers a shutdown function to uninstall itself. The ttf addon forgets to do the same:

https://github.com/liballeg/allegro5/blob/master/addons/ttf/ttf.c#L1104

--
"Either help out or stop whining" - Evert

Go to: