Fixed glyphs being added to partially out-of-bounds positions in Font texture atlases in rare cases (resolves issue #1162).

This commit is contained in:
Alex Szpakowski
2016-05-11 21:38:12 -03:00
parent 9bebe9e4e8
commit d6310ca87f
+10 -19
View File
@@ -252,7 +252,7 @@ love::font::GlyphData *Font::getRasterizerGlyphData(uint32 glyph)
const Font::Glyph &Font::addGlyph(uint32 glyph) const Font::Glyph &Font::addGlyph(uint32 glyph)
{ {
love::font::GlyphData *gd = getRasterizerGlyphData(glyph); StrongRef<love::font::GlyphData> gd(getRasterizerGlyphData(glyph), Acquire::NORETAIN);
int w = gd->getWidth(); int w = gd->getWidth();
int h = gd->getHeight(); int h = gd->getHeight();
@@ -264,18 +264,15 @@ const Font::Glyph &Font::addGlyph(uint32 glyph)
textureY += rowHeight; textureY += rowHeight;
rowHeight = TEXTURE_PADDING; rowHeight = TEXTURE_PADDING;
} }
if (textureY + h + TEXTURE_PADDING > textureHeight) if (textureY + h + TEXTURE_PADDING > textureHeight)
{ {
// totally out of space - new texture! // totally out of space - new texture!
try createTexture();
{
createTexture(); // Makes sure the above code for checking if the glyph can fit at
} // the current position in the texture is run again for this glyph.
catch (love::Exception &) return addGlyph(glyph);
{
gd->release();
throw;
}
} }
Glyph g; Glyph g;
@@ -318,18 +315,12 @@ const Font::Glyph &Font::addGlyph(uint32 glyph)
g.vertices[i].x += gd->getBearingX(); g.vertices[i].x += gd->getBearingX();
g.vertices[i].y -= gd->getBearingY(); g.vertices[i].y -= gd->getBearingY();
} }
textureX += w + TEXTURE_PADDING;
rowHeight = std::max(rowHeight, h + TEXTURE_PADDING);
} }
if (w > 0)
textureX += (w + TEXTURE_PADDING);
if (h > 0)
rowHeight = std::max(rowHeight, h + TEXTURE_PADDING);
gd->release();
const auto p = glyphs.insert(std::make_pair(glyph, g)); const auto p = glyphs.insert(std::make_pair(glyph, g));
return p.first->second; return p.first->second;
} }