All pastes #1966312 Raw Edit

Unnamed

public diff v1 · immutable
#1966312 ·published 2010-10-18 22:54 UTC
rendered paste body
From a7089fc29167145ee2bfa3357c1c4540207c2a99 Mon Sep 17 00:00:00 2001From: Andrei Karas <akaras@inbox.ru>Date: Tue, 19 Oct 2010 01:52:47 +0300Subject: [PATCH] Fix crash in drawing incorrect strings.--- src/gui/truetypefont.cpp |   22 +++++++++++----------- 1 files changed, 11 insertions(+), 11 deletions(-)diff --git a/src/gui/truetypefont.cpp b/src/gui/truetypefont.cppindex e2ae5b9..ebc01ec 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;         }     } -- 1.7.2.3