diff options
author | Andrei Karas <akaras@inbox.ru> | 2010-10-19 01:52:47 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2010-10-19 02:13:24 +0300 |
commit | a9bcae9f81d97f67ab21cd26a099449cf0746137 (patch) | |
tree | 675bc5527f2967baae073cc6462de96b2cca1de0 /src/gui | |
parent | 82183b30b62e3bc9030e30bbfafdde3846ad9856 (diff) | |
download | mana-a9bcae9f81d97f67ab21cd26a099449cf0746137.tar.gz mana-a9bcae9f81d97f67ab21cd26a099449cf0746137.tar.bz2 mana-a9bcae9f81d97f67ab21cd26a099449cf0746137.tar.xz mana-a9bcae9f81d97f67ab21cd26a099449cf0746137.zip |
Fix crash in drawing incorrect strings.
Reviewed-by: cody
Diffstat (limited to 'src/gui')
-rw-r--r-- | src/gui/truetypefont.cpp | 22 |
1 files changed, 11 insertions, 11 deletions
diff --git a/src/gui/truetypefont.cpp b/src/gui/truetypefont.cpp index e2ae5b93..ebc01ec7 100644 --- a/src/gui/truetypefont.cpp +++ b/src/gui/truetypefont.cpp @@ -64,8 +64,8 @@ class TextChunk if (!surface) { - throw "Rendering font to surface failed: " + - std::string(TTF_GetError()); + img = 0; + return; } img = Image::load(surface); @@ -108,9 +108,7 @@ TrueTypeFont::~TrueTypeFont() --fontCounter; if (fontCounter == 0) - { TTF_Quit(); - } } void TrueTypeFont::drawString(gcn::Graphics *graphics, @@ -123,9 +121,7 @@ void TrueTypeFont::drawString(gcn::Graphics *graphics, Graphics *g = dynamic_cast<Graphics *>(graphics); if (!g) - { throw "Not a valid graphics object!"; - } gcn::Color col = g->getColor(); const float alpha = col.a / 255.0f; @@ -154,15 +150,16 @@ void TrueTypeFont::drawString(gcn::Graphics *graphics, if (!found) { if (mCache.size() >= CACHE_SIZE) - { mCache.pop_back(); - } mCache.push_front(chunk); mCache.front().generate(mFont); } - mCache.front().img->setAlpha(alpha); - g->drawImage(mCache.front().img, x, y); + if (mCache.front().img) + { + mCache.front().img->setAlpha(alpha); + g->drawImage(mCache.front().img, x, y); + } } int TrueTypeFont::getWidth(const std::string &text) const @@ -174,7 +171,10 @@ int TrueTypeFont::getWidth(const std::string &text) const // Raise priority: move it to front // Assumption is that TTF::draw will be called next mCache.splice(mCache.begin(), mCache, i); - return i->img->getWidth(); + if (i->img) + return i->img->getWidth(); + else + return 0; } } |