mirror of
https://github.com/love2d/love.git
synced 2026-08-20 20:49:54 +02:00
Fixed a case of undefined behavior in love.graphics.printf and Text:set.
--HG-- branch : minor
This commit is contained in:
@@ -472,16 +472,19 @@ std::vector<Font::DrawCommand> Font::generateVerticesFormatted(const std::string
|
|||||||
|
|
||||||
if (!commands.empty())
|
if (!commands.empty())
|
||||||
{
|
{
|
||||||
|
auto firstcmd = commands.begin();
|
||||||
|
|
||||||
// If the first draw command in the new list has the same texture
|
// If the first draw command in the new list has the same texture
|
||||||
// as the last one in the existing list we're building and its
|
// as the last one in the existing list we're building and its
|
||||||
// vertices are in-order, we can combine them (saving a draw call.)
|
// vertices are in-order, we can combine them (saving a draw call.)
|
||||||
auto firstcmd = commands.begin();
|
if (!drawcommands.empty())
|
||||||
auto prevcmd = drawcommands.back();
|
|
||||||
if (!drawcommands.empty() && prevcmd.texture == firstcmd->texture
|
|
||||||
&& (prevcmd.startvertex + prevcmd.vertexcount) == firstcmd->startvertex)
|
|
||||||
{
|
{
|
||||||
drawcommands.back().vertexcount += firstcmd->vertexcount;
|
auto prevcmd = drawcommands.back();
|
||||||
++firstcmd;
|
if (prevcmd.texture == firstcmd->texture && (prevcmd.startvertex + prevcmd.vertexcount) == firstcmd->startvertex)
|
||||||
|
{
|
||||||
|
drawcommands.back().vertexcount += firstcmd->vertexcount;
|
||||||
|
++firstcmd;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Append the new draw commands to the list we're building.
|
// Append the new draw commands to the list we're building.
|
||||||
|
|||||||
@@ -138,16 +138,19 @@ void Text::addTextData(const TextData &t)
|
|||||||
for (Font::DrawCommand &cmd : new_commands)
|
for (Font::DrawCommand &cmd : new_commands)
|
||||||
cmd.startvertex += (int) voffset;
|
cmd.startvertex += (int) voffset;
|
||||||
|
|
||||||
|
auto firstcmd = new_commands.begin();
|
||||||
|
|
||||||
// If the first draw command in the new list has the same texture as the
|
// If the first draw command in the new list has the same texture as the
|
||||||
// last one in the existing list we're building and its vertices are
|
// last one in the existing list we're building and its vertices are
|
||||||
// in-order, we can combine them (saving a draw call.)
|
// in-order, we can combine them (saving a draw call.)
|
||||||
auto firstcmd = new_commands.begin();
|
if (!draw_commands.empty())
|
||||||
auto prevcmd = draw_commands.back();
|
|
||||||
if (!draw_commands.empty() && prevcmd.texture == firstcmd->texture
|
|
||||||
&& (prevcmd.startvertex + prevcmd.vertexcount) == firstcmd->startvertex)
|
|
||||||
{
|
{
|
||||||
draw_commands.back().vertexcount += firstcmd->vertexcount;
|
auto prevcmd = draw_commands.back();
|
||||||
++firstcmd;
|
if (prevcmd.texture == firstcmd->texture && (prevcmd.startvertex + prevcmd.vertexcount) == firstcmd->startvertex)
|
||||||
|
{
|
||||||
|
draw_commands.back().vertexcount += firstcmd->vertexcount;
|
||||||
|
++firstcmd;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Append the new draw commands to the list we're building.
|
// Append the new draw commands to the list we're building.
|
||||||
|
|||||||
Reference in New Issue
Block a user