mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2025-12-21 14:53:02 +01:00
Fix #23867: Crash when viewing 2 line 3D signs with 16 spaces
This commit is contained in:
@@ -262,41 +262,34 @@ static void PaintLargeScenery3DText(
|
|||||||
CodepointView view(current);
|
CodepointView view(current);
|
||||||
auto lineWidth = 0;
|
auto lineWidth = 0;
|
||||||
auto it = view.begin();
|
auto it = view.begin();
|
||||||
while (it != view.end() && lineWidth < text->max_width)
|
size_t lastWhitespaceIndex = 0;
|
||||||
|
while (it != view.end())
|
||||||
{
|
{
|
||||||
// Trim any leading spaces
|
const auto codepoint = *it;
|
||||||
auto codepoint = *it;
|
const auto glyph = text->GetGlyph(codepoint, ' ');
|
||||||
if (codepoint != ' ' || lineWidth != 0)
|
lineWidth += glyph.width;
|
||||||
|
|
||||||
|
if (codepoint == ' ')
|
||||||
{
|
{
|
||||||
// Determine if this is a good place to split
|
lastWhitespaceIndex = it.GetIndex();
|
||||||
if (codepoint == ' ' || codepoint == '\n')
|
}
|
||||||
|
|
||||||
|
if (lineWidth > text->max_width)
|
||||||
{
|
{
|
||||||
auto index = it.GetIndex();
|
|
||||||
best = current.substr(0, index);
|
|
||||||
next = current.substr(index + 1);
|
|
||||||
if (codepoint == '\n')
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto glyph = text->GetGlyph(*it, ' ');
|
|
||||||
lineWidth += glyph.width;
|
|
||||||
}
|
|
||||||
it++;
|
it++;
|
||||||
|
|
||||||
|
const auto index = it.GetIndex();
|
||||||
|
best = current.substr(0, index);
|
||||||
|
next = current.substr(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
// handle case where second line fully fits
|
if (lastWhitespaceIndex != 0 && it != view.end())
|
||||||
if (it == view.end() && lineWidth < text->max_width)
|
|
||||||
{
|
{
|
||||||
best = current;
|
best = current.substr(0, lastWhitespaceIndex);
|
||||||
next = std::string_view{};
|
next = current.substr(lastWhitespaceIndex + 1);
|
||||||
}
|
|
||||||
|
|
||||||
if (best.empty())
|
|
||||||
{
|
|
||||||
// No good split found, or reached end of string
|
|
||||||
auto index = it.GetIndex();
|
|
||||||
best = current.substr(0, index - 1);
|
|
||||||
next = current.substr(index - 1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
PaintLargeScenery3DTextLine(session, sceneryEntry, *text, best, imageTemplate, direction, offsetY);
|
PaintLargeScenery3DTextLine(session, sceneryEntry, *text, best, imageTemplate, direction, offsetY);
|
||||||
|
|||||||
Reference in New Issue
Block a user