summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGuillaume Melquiond <guillaume.melquiond@gmail.com>2007-10-18 11:12:42 +0000
committerBjørn Lindeijer <bjorn@lindeijer.nl>2008-12-29 15:28:53 +0100
commit883548ac5601a06e680bc0e272b4520ecaf4ff03 (patch)
tree86932d3d71c5683ec01caf90532f368777e4d0c6 /src
parent0a798c4225dda1f62100070ff3a4414a27fa8cb8 (diff)
downloadmana-883548ac5601a06e680bc0e272b4520ecaf4ff03.tar.gz
mana-883548ac5601a06e680bc0e272b4520ecaf4ff03.tar.bz2
mana-883548ac5601a06e680bc0e272b4520ecaf4ff03.tar.xz
mana-883548ac5601a06e680bc0e272b4520ecaf4ff03.zip
Fixed double-free of true-type resources.
(cherry-picked from mainline)
Diffstat (limited to 'src')
-rw-r--r--src/gui/truetypefont.cpp7
1 files changed, 5 insertions, 2 deletions
diff --git a/src/gui/truetypefont.cpp b/src/gui/truetypefont.cpp
index bf95ca37..3986cca5 100644
--- a/src/gui/truetypefont.cpp
+++ b/src/gui/truetypefont.cpp
@@ -82,15 +82,17 @@ class TextChunk
static std::list<TextChunk> cache;
typedef std::list<TextChunk>::iterator CacheIterator;
+static int fontCounter;
TrueTypeFont::TrueTypeFont(const std::string& filename, int size)
{
- if (!TTF_WasInit() && TTF_Init() == -1)
+ if (fontCounter == 0 && TTF_Init() == -1)
{
throw GCN_EXCEPTION("Unable to initialize SDL_ttf: " +
std::string(TTF_GetError()));
}
+ ++fontCounter;
mFont = TTF_OpenFont(filename.c_str(), size);
if (mFont == NULL)
@@ -103,8 +105,9 @@ TrueTypeFont::TrueTypeFont(const std::string& filename, int size)
TrueTypeFont::~TrueTypeFont()
{
TTF_CloseFont(mFont);
+ --fontCounter;
- if (TTF_WasInit())
+ if (fontCounter == 0)
{
TTF_Quit();
}