mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2025-12-10 09:32:29 +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);
|
||||
auto lineWidth = 0;
|
||||
auto it = view.begin();
|
||||
while (it != view.end() && lineWidth < text->max_width)
|
||||
size_t lastWhitespaceIndex = 0;
|
||||
while (it != view.end())
|
||||
{
|
||||
// Trim any leading spaces
|
||||
auto codepoint = *it;
|
||||
if (codepoint != ' ' || lineWidth != 0)
|
||||
const auto codepoint = *it;
|
||||
const auto glyph = text->GetGlyph(codepoint, ' ');
|
||||
lineWidth += glyph.width;
|
||||
|
||||
if (codepoint == ' ')
|
||||
{
|
||||
// Determine if this is a good place to split
|
||||
if (codepoint == ' ' || codepoint == '\n')
|
||||
{
|
||||
auto index = it.GetIndex();
|
||||
best = current.substr(0, index);
|
||||
next = current.substr(index + 1);
|
||||
if (codepoint == '\n')
|
||||
break;
|
||||
}
|
||||
|
||||
auto glyph = text->GetGlyph(*it, ' ');
|
||||
lineWidth += glyph.width;
|
||||
lastWhitespaceIndex = it.GetIndex();
|
||||
}
|
||||
|
||||
if (lineWidth > text->max_width)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
it++;
|
||||
|
||||
const auto index = it.GetIndex();
|
||||
best = current.substr(0, index);
|
||||
next = current.substr(index);
|
||||
}
|
||||
|
||||
// handle case where second line fully fits
|
||||
if (it == view.end() && lineWidth < text->max_width)
|
||||
if (lastWhitespaceIndex != 0 && it != view.end())
|
||||
{
|
||||
best = current;
|
||||
next = std::string_view{};
|
||||
}
|
||||
|
||||
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);
|
||||
best = current.substr(0, lastWhitespaceIndex);
|
||||
next = current.substr(lastWhitespaceIndex + 1);
|
||||
}
|
||||
|
||||
PaintLargeScenery3DTextLine(session, sceneryEntry, *text, best, imageTemplate, direction, offsetY);
|
||||
|
||||
Reference in New Issue
Block a user