Skip to content

Reproducible "Fatal error: 2 is out of bounds. Valid range is 0 - 0" with specific content #415

@Timac

Description

@Timac

What happened?

When you replace the specific content "X-X\n" with "XX\n" using "self.contentView.textView.text", you can always reproduce the error:

Runestone/RedBlackTree.swift:39: Fatal error: 2 is out of bounds. Valid range is 0 - 0. This issue is under investigation. Please open an issue at https://github.com/simonbs/Runestone/issues and include this stack trace and a sample text file if possible. This fatal error is only thrown in debug builds.

Reproducible with

  • iPhone 15 Pro with iOS 26.1
  • Xcode 26.1 (17B55)

Please see attached video

What are the steps to reproduce?

  1. Add code to execute self.contentView.textView.text = "XX\n"

    For example:

    extension MainViewController: MenuSelectionHandler {
        // swiftlint:disable:next cyclomatic_complexity
        func handleSelection(of menuItem: MenuItem) {
            switch menuItem {
    

    to

    extension MainViewController: MenuSelectionHandler {
        // swiftlint:disable:next cyclomatic_complexity
        func handleSelection(of menuItem: MenuItem) {
             debugPrint("**** WILL CHANGE!")
             self.contentView.textView.text = "XX\n"
             debugPrint("**** DID CHANGE!")
            switch menuItem {
    
  2. Compile and run the Example app

  3. Type in the UI "X-X\n". Note that you need to type or paste this text.

  4. Tap on More > Find to trigger the code self.contentView.textView.text = "XX\n"

Result:

"**** WILL CHANGE!"
Runestone/RedBlackTree.swift:39: Fatal error: 2 is out of bounds. Valid range is 0 - 0. This issue is under investigation. Please open an issue at https://github.com/simonbs/Runestone/issues and include this stack trace and a sample text file if possible. This fatal error is only thrown in debug builds.
video.mov

What is the expected behavior?

Such an error should not occur.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions