Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clicking into a reasonably long Markdown file crashes #377

Open
aoverholtzer opened this issue Jul 2, 2024 · 0 comments
Open

Clicking into a reasonably long Markdown file crashes #377

aoverholtzer opened this issue Jul 2, 2024 · 0 comments
Assignees
Labels
bug Something isn't working

Comments

@aoverholtzer
Copy link

What happened?

Loading a "reasonably long" Markdown file and then attempting to click to place the cursor crashes reliably on Mac Catalyst in DEBUG mode. I've seen this on iOS too but have not figured out a way to reliably reproduce.

Runestone/RedBlackTree.swift:39: Fatal error: 5295 is out of bounds. Valid range is 0 - 5291. 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.

Here is the fatalError in the code and a full stack trace:

fatalError("\(location) is out of bounds. Valid range is \(minimumValue) - \(root.nodeTotalValue)."

* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BREAKPOINT (code=1, subcode=0x1a17e5ee0)
    frame #0: 0x00000001a17e5ee0 libswiftCore.dylib`Swift._assertionFailure(_: Swift.StaticString, _: Swift.String, file: Swift.StaticString, line: Swift.UInt, flags: Swift.UInt32) -> Swift.Never + 268
  * frame #1: 0x0000000102391d6c RunestonePlayground`RedBlackTree.node(location=5295, self=0x0000600000836be0) at RedBlackTree.swift:39:13
    frame #2: 0x0000000102412494 RunestonePlayground`LineController.lineFragmentNode(location=5295, self=0x000060000339e340) at LineController.swift:166:26
    frame #3: 0x0000000102453520 RunestonePlayground`CaretRectService.shouldMoveCaretToNextLineFragment(location=5295, line=0x0000600002dbd260, self=0x00006000022a0420) at CaretRectService.swift:52:53
    frame #4: 0x00000001024531e0 RunestonePlayground`CaretRectService.caretRect(location=5295, allowMovingCaretToNextLineFragment=true, self=0x00006000022a0420) at CaretRectService.swift:34:47
    frame #5: 0x0000000102453fec RunestonePlayground`SelectionRectService.selectionRects(range=location=5295, length=2, self=0x00006000022a0540) at SelectionRectService.swift:32:47
    frame #6: 0x00000001023e2a1c RunestonePlayground`TextInputView.selectionRects(range=0x0000600000613900, self=0x000000012a64be90) at TextInputView.swift:1336:41
    frame #7: 0x00000001023e2ae4 RunestonePlayground`@objc TextInputView.selectionRects(for:) at <compiler-generated>:0
    frame #8: 0x00000001c1bd8858 UIKitCore`-[UIKBRTIPartner _queryUIKitDocumentRequest:completion:] + 3360
    frame #9: 0x00000001c1bd686c UIKitCore`-[UIKBRTIPartner _queryDocumentRequest:completion:] + 136
    frame #10: 0x00000001c1bd0b58 UIKitCore`-[UIKBRTIPartner _updateRTIStateWithCompletion:] + 312
    frame #11: 0x00000001c1bcf8dc UIKitCore`-[UIKBRTIPartner updateStateWithCompletion:updateTraits:] + 144
    frame #12: 0x00000001c1bcb9e0 UIKitCore`-[UIKBRTIPartner beginInputSessionWithIdentifier:] + 280
    frame #13: 0x00000001c1b39684 UIKitCore`-[UIKeyboardImpl _setupDelegate:delegateSame:hardwareKeyboardStateChanged:endingInputSessionIdentifier:force:delayEndInputSession:] + 3940
    frame #14: 0x00000001c1b36f7c UIKitCore`-[UIKeyboardImpl setDelegate:force:delayEndInputSession:] + 712
    frame #15: 0x00000001c17ee28c UIKitCore`-[UIKeyboardSceneDelegate _reloadInputViewsForKeyWindowSceneResponder:force:fromBecomeFirstResponder:] + 2764
    frame #16: 0x00000001c17ed494 UIKitCore`-[UIKeyboardSceneDelegate _reloadInputViewsForResponder:force:fromBecomeFirstResponder:] + 88
    frame #17: 0x00000001c1d48eb0 UIKitCore`-[UIResponder(UIResponderInputViewAdditions) _reloadInputViewsFromFirstResponder:] + 88
    frame #18: 0x00000001c1106958 UIKitCore`-[UIResponder becomeFirstResponder] + 628
    frame #19: 0x00000001c112a640 UIKitCore`-[UIView(Hierarchy) becomeFirstResponder] + 120
    frame #20: 0x00000001023d75c0 RunestonePlayground`TextInputView.becomeFirstResponder(self=0x000000012a64be90) at TextInputView.swift:670:45
    frame #21: 0x00000001023f1fe4 RunestonePlayground`TextView.becomeFirstResponder(self=0x000000012a89ee00) at TextView.swift:696:31
    frame #22: 0x00000001023f2040 RunestonePlayground`@objc TextView.becomeFirstResponder() at <compiler-generated>:0
    frame #23: 0x00000001023f4e9c RunestonePlayground`TextView.handleTap(gestureRecognizer=0x000000012a6458a0, self=0x000000012a89ee00) at TextView.swift:1135:13
    frame #24: 0x00000001023f5224 RunestonePlayground`@objc TextView.handleTap(_:) at <compiler-generated>:0
    frame #25: 0x00000001c1211494 UIKitCore`-[UIGestureRecognizerTarget _sendActionWithGestureRecognizer:] + 124
    frame #26: 0x00000001c1211308 UIKitCore`_UIGestureRecognizerSendTargetActions + 92
    frame #27: 0x00000001c12110c8 UIKitCore`_UIGestureRecognizerSendActions + 264
    frame #28: 0x00000001c190c6cc UIKitCore`-[UIGestureRecognizer _updateGestureForActiveEvents] + 516
    frame #29: 0x00000001c1028d90 UIKitCore`_UIGestureEnvironmentUpdate + 2448
    frame #30: 0x00000001c120c184 UIKitCore`-[UIGestureEnvironment _deliverEvent:toGestureRecognizers:usingBlock:] + 296
    frame #31: 0x00000001c120bc94 UIKitCore`-[UIGestureEnvironment _updateForEvent:window:] + 188
    frame #32: 0x00000001c120b948 UIKitCore`-[UIWindow sendEvent:] + 3132
    frame #33: 0x00000001c120a580 UIKitCore`-[UIApplication sendEvent:] + 564
    frame #34: 0x00000001c1208750 UIKitCore`__dispatchPreprocessedEventFromEventQueue + 6448
    frame #35: 0x00000001c1da3368 UIKitCore`__processEventQueue + 5508
    frame #36: 0x00000001c1d9d714 UIKitCore`__eventFetcherSourceCallback + 152
    frame #37: 0x0000000191bc24d8 CoreFoundation`__CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 28
    frame #38: 0x0000000191bc246c CoreFoundation`__CFRunLoopDoSource0 + 176
    frame #39: 0x0000000191bc21dc CoreFoundation`__CFRunLoopDoSources0 + 244
    frame #40: 0x0000000191bc0dc8 CoreFoundation`__CFRunLoopRun + 828
    frame #41: 0x0000000191bc0434 CoreFoundation`CFRunLoopRunSpecific + 608
    frame #42: 0x000000019c36419c HIToolbox`RunCurrentEventLoopInMode + 292
    frame #43: 0x000000019c363e2c HIToolbox`ReceiveNextEventCommon + 220
    frame #44: 0x000000019c363d30 HIToolbox`_BlockUntilNextEventMatchingListInModeWithFilter + 76
    frame #45: 0x000000019541fd68 AppKit`_DPSNextEvent + 660
    frame #46: 0x0000000195c15808 AppKit`-[NSApplication(NSEventRouting) _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 700
    frame #47: 0x000000019541309c AppKit`-[NSApplication run] + 476
    frame #48: 0x00000001953ea2e0 AppKit`NSApplicationMain + 880
    frame #49: 0x000000019563da30 AppKit`_NSApplicationMainWithInfoDictionary + 24
    frame #50: 0x00000001aae8af40 UIKitMacHelper`UINSApplicationMain + 972
    frame #51: 0x00000001c1017570 UIKitCore`UIApplicationMain + 148
    frame #52: 0x00000001c12f2a64 UIKitCore`UIKit.UIApplicationMain(Swift.Int32, Swift.Optional<Swift.UnsafeMutablePointer<Swift.UnsafeMutablePointer<Swift.Int8>>>, Swift.Optional<Swift.String>, Swift.Optional<Swift.String>) -> Swift.Int32 + 104
    frame #53: 0x00000001022fc154 RunestonePlayground`static UIApplicationDelegate.main() at <compiler-generated>:0
    frame #54: 0x00000001022fc0cc RunestonePlayground`static AppDelegate.$main(self=@thick RunestonePlayground.AppDelegate.Type) at <compiler-generated>:0
    frame #55: 0x00000001022fc1d0 RunestonePlayground`main at AppDelegate.swift:11:7
    frame #56: 0x000000019175a0e0 dyld`start + 2360

What are the steps to reproduce?

Step 1:
Add the Markdown language frameworks to the Example project.

Step 2:
Create "reasonably long" text and load it as Markdown:

let text = String(repeating: "test *and* ", count: 10_000)

DispatchQueue.global(qos: .userInitiated).async {
    let state = TextViewState(text: text, theme: OneDarkTheme(), language: .markdownInline)
    DispatchQueue.main.async {
        textView.setState(state)
    }
}

Step 3:
Run the app in Mac Catalyst. Once the text loads, scroll down a few lines and then click to place the cursor.

What is the expected behavior?

I expect TextView to become first responder and place the cursor at the location clicked.

@aoverholtzer aoverholtzer added the bug Something isn't working label Jul 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants