summaryrefslogtreecommitdiffstats
path: root/src/graphics
diff options
context:
space:
mode:
authorPiotr Dziwinski <piotrdz@gmail.com>2013-10-12 21:12:54 +0200
committerPiotr Dziwinski <piotrdz@gmail.com>2013-10-12 21:14:33 +0200
commitccb63bd29e0cc7957be53cb40889496d04527d7a (patch)
treef83aaf4154fb91afd70ed84df016268baf11e3f7 /src/graphics
parent5d0d9b5aa5cf19aff9edb42701d38b5096fce3aa (diff)
downloadcolobot-ccb63bd29e0cc7957be53cb40889496d04527d7a.tar.gz
colobot-ccb63bd29e0cc7957be53cb40889496d04527d7a.tar.bz2
colobot-ccb63bd29e0cc7957be53cb40889496d04527d7a.zip
Fixed memory leaks in CText
Diffstat (limited to 'src/graphics')
-rw-r--r--src/graphics/engine/text.cpp23
1 files changed, 18 insertions, 5 deletions
diff --git a/src/graphics/engine/text.cpp b/src/graphics/engine/text.cpp
index 610bfcf..ffd2eb2 100644
--- a/src/graphics/engine/text.cpp
+++ b/src/graphics/engine/text.cpp
@@ -140,6 +140,12 @@ void CText::FlushCache()
for (auto jt = mf->fonts.begin(); jt != mf->fonts.end(); ++jt)
{
CachedFont *f = (*jt).second;
+ for (auto ct = f->cache.begin(); ct != f->cache.end(); ++ct)
+ {
+ Texture tex;
+ tex.id = (*ct).second.id;
+ m_device->DestroyTexture(tex);
+ }
f->cache.clear();
}
}
@@ -358,14 +364,22 @@ float CText::GetCharWidth(UTF8Char ch, FontType font, float size, float offset)
CachedFont* cf = GetOrOpenFont(font, size);
assert(cf != nullptr);
- CharTexture tex;
+ Math::Point charSize;
auto it = cf->cache.find(ch);
if (it != cf->cache.end())
- tex = (*it).second;
+ {
+ charSize = (*it).second.charSize;
+ }
else
- tex = CreateCharTexture(ch, cf);
+ {
+ Math::IntPoint wndSize;
+ std::string text;
+ text.append({ch.c1, ch.c2, ch.c3});
+ TTF_SizeUTF8(cf->font, text.c_str(), &wndSize.x, &wndSize.y);
+ charSize = m_engine->WindowToInterfaceSize(wndSize);
+ }
- return tex.charSize.x * width;
+ return charSize.x * width;
}
@@ -896,7 +910,6 @@ CharTexture CText::CreateCharTexture(UTF8Char ch, CachedFont* font)
if (! tex.Valid())
{
m_error = "Texture create error";
- return texture;
}
else
{