Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: TextBlock enters an infinite loop if the given available space is too small to fit even one character. #2598

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions sources/engine/Stride.UI/Controls/TextBlock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@ private void UpdateWrappedText(Vector3 availableSpace)
float lineCurrentSize;
var indexNextCharacter = 0;
var indexOfLastSpace = -1;
char currentCharacter = text[0];

while (true)
{
Expand All @@ -304,7 +305,7 @@ private void UpdateWrappedText(Vector3 availableSpace)
if (lineCurrentSize > availableWidth || indexOfNewLine + indexNextCharacter >= text.Length)
break;

var currentCharacter = text[indexOfNewLine + indexNextCharacter];
currentCharacter = text[indexOfNewLine + indexNextCharacter];

if (currentCharacter == '\n')
{
Expand All @@ -329,7 +330,13 @@ private void UpdateWrappedText(Vector3 availableSpace)
}

// we reached the end of the line.
if (indexOfLastSpace < 0) // no space in the line
if (currentLine.Length <= 1 || CalculateTextSize(currentLine).X <= 0) // just one or all empty characters... just go one by one.
{
currentLine.Clear();
currentLine.Append(currentCharacter);
indexOfNewLine += indexNextCharacter;
}
else if (indexOfLastSpace < 0) // no space in the line
{
// remove last extra character
currentLine.Remove(currentLine.Length - 1, 1);
Expand Down