Skip to content

Fix crash when pasting into text editor - #397

Closed
nacklequack wants to merge 1 commit into
AlchemyViewer:developfrom
nacklequack:fix/lsl-paste-crash
Closed

nacklequack wants to merge 1 commit into
AlchemyViewer:developfrom
nacklequack:fix/lsl-paste-crash

Conversation

@nacklequack

Copy link
Copy Markdown
Contributor

Description

Fixes an intermittent viewer crash observed while pasting source code into an LSL script editor.

A native crash dump from Alchemy Test 26.4.0.63546 showed the following failure path:

std::string_view::_Check_offset → std::string_view::substr → LLTextEditor::getLineColumnFromDocIndex

Text changes invalidate the cached line layout and reflow it lazily. During that interval, a cursor position can be valid for the updated document while extending beyond the final cached line. getLineOffsetFromDocIndex() did not handle std::upper_bound() returning end(), resulting in an invalid line start being passed to std::string_view::substr().

This change:

  • Handles cursor positions beyond the last cached line while layout is stale.
  • Clamps document and line-start positions to the current UTF-8 text bounds before calculating the displayed column.
  • Preserves existing behavior after the line layout has been refreshed.

Reproduction

  1. Open an LSL script in the built-in editor.
  2. Paste a block of source code into the editor.
  3. Under the affected timing, the viewer terminates during the editor's line/column update.

Related Issues

  • Please link to a relevant GitHub issue for additional context.
    • Bug Fix: Link to an issue that includes reproduction steps and testing guidance.
    • Feature/Enhancement: Link to an issue with a write-up, rationale, and requirements.

Issue Link: None filed


Checklist

Please ensure the following before requesting review:

  • I have provided a clear title and detailed description for this pull request.
  • If useful, I have included media such as screenshots and video to show off my changes.
  • I have tested the changes locally and verified they work as intended.
  • All new and existing tests pass. The configured build contains no registered tests (ctest reported Total Tests: 0).
  • Code follows the project's style guidelines.
  • Documentation has been updated if needed. No documentation changes are required.
  • Any dependent changes have been merged and published in downstream modules. There are no dependent changes.
  • I have reviewed the contributing guidelines.

Additional Notes

The complete Windows Release viewer was rebuilt successfully with:

cmake --build build-Windows-vs2026-os --config Release

The patched build remained stable through a full day of use, and the original crash did not recur.

The native dump and Windows Application Error event were analyzed locally. The event reported exception code 0xc0000409; the symbolized dump identified the bounds-check failure described above.

Handle cursor positions beyond stale cached line layout and clamp UTF-8 column calculations to the current document bounds.
@coderabbitai

coderabbitai Bot commented Sep 11, 2026 •

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: 2ce35134-a9c8-4b1b-a4eb-deb641adefc0

📥 Commits

Reviewing files that changed from the base of the PR and between 3c8cb82 and 6db4871.

📒 Files selected for processing (2)
  • indra/llui/lltextbase.cpp
  • indra/llui/lltexteditor.cpp

Included review availability: Your plan provides up to 1 included review per hour; 0 remain after this review.


📝 Summary

Summary by CodeRabbit

  • Bug Fixes
    • Improved text cursor positioning when editing content before layout updates complete.
    • Fixed line and column calculations for cursor positions near or beyond the end of a document.
    • Prevented invalid cursor spans and related display inconsistencies when text changes rapidly or exceeds the currently rendered layout.

Walkthrough

The text UI now handles cursor positions beyond cached lines and clamps document indices before calculating line-column spans.

Changes

Text cursor safety

Layer / File(s) Summary
Cursor index guards
indra/llui/lltextbase.cpp, indra/llui/lltexteditor.cpp
Line offset lookup handles positions beyond the last cached line. Line-column calculation clamps document and line-start indices before deriving the span.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~10 minutes

Suggested reviewers: ryemutt

Merge Risk: ⚪ Minimal · up to 6db48

The text editor now safely handles cursor positions while layout reflow is pending, with no unresolved merge-blocking risk identified.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 3 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: fixing a crash that occurs when pasting into the text editor.
Description check ✅ Passed The description is detailed and follows the repository template. It explains the crash, root cause, implementation, reproduction steps, testing, and build results. No issue link was provided, but the …
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
  • Fix all pre-merge checks with AI

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

A rabbit hops past cached lines,
And keeps each cursor count in bounds.
No dangling ends, no backward spans,
Just tidy text through leafy lands.
The editor thumps its paws: all sound!

Comment @coderabbitai help to get the list of available commands.

Shadowolf7 pushed a commit to Shadowolf7/Vayu-Viewer that referenced this pull request Sep 15, 2026
Text changes invalidate line layout lazily. During that interval,
a valid cursor in newly updated text can sit beyond the last cached line.
getLineOffsetFromDocIndex() did not handle std::upper_bound() returning
end(), causing an invalid line offset and out-of-bounds substr crash.

- Handle cursor positions beyond the last cached line while layout is pending
- Clamp document and line-start bounds before computing column span

Ported from Alchemy PR AlchemyViewer#397 by nacklequack.
@RyeMutt

RyeMutt commented Sep 18, 2026

Copy link
Copy Markdown
Member

Integrated in 9157c4a

@RyeMutt RyeMutt closed this Sep 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants