Skip to content

Text: fix splitRawText infinite loop when wrap width is below one glyph - #1374

Open
hoseyjoe wants to merge 1 commit into
HeapsIO:masterfrom
hoseyjoe:fix-splitrawtext-hang
Open

hoseyjoe wants to merge 1 commit into
HeapsIO:masterfrom
hoseyjoe:fix-splitrawtext-hang

Conversation

@hoseyjoe

@hoseyjoe hoseyjoe commented Oct 3, 2026

Copy link
Copy Markdown

Text: fix splitRawText infinite loop when wrap width is below one glyph

Fixes HeapsIO/heaps#1347 (repro attached there).

When a break char already overflows maxWidth, lastBreak is set to i - 1, which can point before the current line start. The rewind then flushes an empty line without advancing i/lastPos, looping forever. This is triggered by e.g. layouts that measure at width 0 first (HaxeUI, Flow constraints), CJK text, or TextInput (trimTrailingSpaces = false).

Requiring lastBreak >= lastPos guarantees each rewind consumes at least one char. It still implies the old lastBreak >= 0 check, and wrapping output at normal widths is unchanged.

When a break char already overflows maxWidth, lastBreak is set to i - 1,
which can point before the start of the current line (lastPos - 1). The
rewind branch then flushes an empty line without advancing i or lastPos,
and the loop repeats forever. This happens e.g. with maxWidth = 0 (layouts
that measure at zero width first) and CJK text, or TextInput with
trimTrailingSpaces = false.

Only rewind to a break point inside the current line, so every rewind
consumes at least one character. lastPos is never negative, so this still
implies the old lastBreak >= 0 check.

Fixes HeapsIO#1347

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

h2d text.hx splitRawText can hang

1 participant