1
0
mirror of git://projects.qi-hardware.com/gmenu2x.git synced 2024-11-25 15:56:15 +02:00

Fix crashes that could occur when keeping two fonts loaded concurrently.

Since 2002-09-03, SDL_ttf performs reference counting on TTF_Init and
TTF_Quit. If two fonts were loaded concurrently via the Font class and
one was destructed, the destructor of the first object would call TTF_Quit,
making the second object unusable. The constructor now calls TTF_Init
unconditionally to prevent this situation.

The reference counting behavior was introduced in this SDL_ttf commit:
http://hg.libsdl.org/SDL_ttf/rev/fc0371908009
This commit is contained in:
Nebuleon Fumika 2014-06-18 04:34:33 +00:00 committed by Maarten ter Huurne
parent c777de258c
commit 738c296c67

View File

@ -21,7 +21,9 @@ Font *Font::defaultFont()
Font::Font(const std::string &path, unsigned int size)
{
if (!TTF_WasInit() && TTF_Init() < 0) {
/* Note: TTF_Init and TTF_Quit perform reference counting, so call them
* both unconditionally for each font. */
if (TTF_Init() < 0) {
ERROR("Unable to init SDL_ttf library\n");
return;
}
@ -35,12 +37,6 @@ Font::Font(const std::string &path, unsigned int size)
fontheight = TTF_FontHeight(font);
}
Font::Font(TTF_Font *font)
: font(font)
{
fontheight = TTF_FontHeight(font);
}
Font::~Font()
{
TTF_CloseFont(font);