mirror of
git://projects.qi-hardware.com/gmenu2x.git
synced 2024-11-22 12:30:18 +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:
parent
c777de258c
commit
738c296c67
10
src/font.cpp
10
src/font.cpp
@ -21,7 +21,9 @@ Font *Font::defaultFont()
|
|||||||
|
|
||||||
Font::Font(const std::string &path, unsigned int size)
|
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");
|
ERROR("Unable to init SDL_ttf library\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -35,12 +37,6 @@ Font::Font(const std::string &path, unsigned int size)
|
|||||||
fontheight = TTF_FontHeight(font);
|
fontheight = TTF_FontHeight(font);
|
||||||
}
|
}
|
||||||
|
|
||||||
Font::Font(TTF_Font *font)
|
|
||||||
: font(font)
|
|
||||||
{
|
|
||||||
fontheight = TTF_FontHeight(font);
|
|
||||||
}
|
|
||||||
|
|
||||||
Font::~Font()
|
Font::~Font()
|
||||||
{
|
{
|
||||||
TTF_CloseFont(font);
|
TTF_CloseFont(font);
|
||||||
|
Loading…
Reference in New Issue
Block a user