Skip to content

Fix crash when rendering text with hundreds of newlines#438

Open
ejud wants to merge 1 commit into
gonzalezreal:mainfrom
ejud:ejud/fix-crash-on-many-newlines
Open

Fix crash when rendering text with hundreds of newlines#438
ejud wants to merge 1 commit into
gonzalezreal:mainfrom
ejud:ejud/fix-crash-on-many-newlines

Conversation

@ejud

@ejud ejud commented Jan 6, 2026

Copy link
Copy Markdown

This is a fix to issue #312, describing a crash when hundreds of newlines exist in markdown. This appears to be device-dependent; my test device needed about 500 lines to crash, and my simulator needed about 3,000.

Diagnosis

  • \n characters split the text into many inline nodes. Text of 500 lines results in 999 nodes (500 lines interlaced with 499 "soft breaks")
  • TextInlineRenderer was using Text concatenation to concatenate attributed strings. Each Text + Text concatenation resulted in a nested Text object.
    • Text + Text + Text is effectively Text(Text + Text) + Text in its implementation.
  • The result of this concatenation is that 500 lines creates a nested depth of somewhere around 999. At this point, a crash is likely.

Solution

TextInlineRenderer deals only with attributed strings and images. Instead of concatenating a Text view for every node, we track the sequences of attributed strings and images separately; when we append an attributed string to another attributed string, we concatenate the strings directly. Only when accessing the final result are these values converted to Text.

In effect, the nesting depth for Text objects is now proportional to the number of images inline, rather than the total number of nodes.

@ejud
ejud marked this pull request as ready for review January 6, 2026 16:43
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.

1 participant