From 11bf1f990329764568f706835d237a9ad4c9f25d Mon Sep 17 00:00:00 2001 From: Jaakko Keränen Date: Sat, 4 Sep 2021 07:21:29 +0300 Subject: Text: Fixed hang when wrapping a long word The simple text renderer would get stuck in an infinite loop when encountering a word that wouldn't fit on a line. IssueID #330 --- src/ui/text_simple.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'src/ui') diff --git a/src/ui/text_simple.c b/src/ui/text_simple.c index 3afc631a..e88b09a8 100644 --- a/src/ui/text_simple.c +++ b/src/ui/text_simple.c @@ -169,6 +169,7 @@ static iRect runSimple_Font_(iFont *d, const iRunArgs *args) { if (!notify_WrapText_(wrap, chPos, 0, iMax(xpos, xposExtend) - orig.x, iFalse)) { break; } + lastWordEnd = NULL; xpos = xposExtend = orig.x; ypos += d->height; prevCh = ch; @@ -240,21 +241,19 @@ static iRect runSimple_Font_(iFont *d, const iRunArgs *args) { iAssert(wrap); const char *wrapPos = currentPos; int advance = x1 - orig.x; - if (lastWordEnd != args->text.start && wrap->mode == word_WrapTextMode) { - wrapPos = skipSpace_CStr(lastWordEnd); + if (lastWordEnd && wrap->mode == word_WrapTextMode) { + wrapPos = skipSpace_CStr(lastWordEnd); /* go back */ wrapPos = iMin(wrapPos, args->text.end); advance = wrapAdvance; } -// if (args->continueFrom_out) { -// *args->continueFrom_out = wrapPos; -// } if (!notify_WrapText_(wrap, wrapPos, 0, advance, iFalse)) { break; } + lastWordEnd = NULL; xpos = xposExtend = orig.x; ypos += d->height; prevCh = 0; - chPos = wrapPos; /* go back */ + chPos = wrapPos; continue; } const int yLineMax = ypos + d->height; -- cgit v1.2.3