kkebo / DevToys.swiftpm

DevToys for iPad (WIP)
MIT License
38 stars 5 forks source link

Markdown Preview crashes when I type specific text #63

Open kkebo opened 6 months ago

kkebo commented 6 months ago

Steps to reproduce

  1. Open DevToys
  2. Type - a
  3. Press the return key
  4. Try to type (two spaces)

Then, the app will crash.

Crash log and my environment

testflight_feedback.zip

Exception Type:  EXC_BREAKPOINT (SIGTRAP)
Exception Codes: 0x0000000000000001, 0x0000000187d5e3c8
Termination Reason: SIGNAL 5 Trace/BPT trap: 5
Terminating Process: exc handler [972]

Triggered by Thread:  0

Thread 0 name:
Thread 0 Crashed:
0   libswiftCore.dylib              0x0000000187d5e3c8 closure #1 in closure #1 in closure #1 in _assertionFailure(_:_:file:line:flags:) + 228 (AssertCommon.swift:108)
1   libswiftCore.dylib              0x0000000187d5e2a0 closure #1 in closure #1 in _assertionFailure(_:_:file:line:flags:) + 332 (AssertCommon.swift:101)
2   libswiftCore.dylib              0x0000000187d5dc2c _assertionFailure(_:_:file:line:flags:) + 184 (AssertCommon.swift:97)
3   libswiftCore.dylib              0x0000000187f22b70 _StringGuts.validateScalarIndex(_:) + 164 (StringIndexValidation.swift:121)
4   libswiftCore.dylib              0x0000000187ebd1c0 String.subscript.getter + 36 (StringCharacterView.swift:315)
5   DevToys                         0x000000010231644c 0x102264000 + 730188
6   DevToys                         0x00000001023166bc 0x102264000 + 730812
7   DevToys                         0x00000001023163c0 0x102264000 + 730048
8   DevToys                         0x0000000102317c00 0x102264000 + 736256
9   DevToys                         0x0000000102310f90 0x102264000 + 708496
10  DevToys                         0x00000001023102ec 0x102264000 + 705260
11  DevToys                         0x000000010230fe38 0x102264000 + 704056
12  DevToys                         0x00000001022b4678 0x102264000 + 329336
13  libswiftObservation.dylib       0x00000002378fbe9c ObservationRegistrar.withMutation<A, B, C>(of:keyPath:_:) + 100 (ObservationRegistrar.swift:364)
14  DevToys                         0x00000001022a60fc 0x102264000 + 270588
15  libswiftCore.dylib              0x0000000187e8a914 NonmutatingWritebackBuffer.__deallocating_deinit + 328 (KeyPath.swift:942)
16  libswiftCore.dylib              0x00000001880cf36c _swift_release_dealloc + 56 (HeapObject.cpp:832)
17  libswiftCore.dylib              0x00000001880d0488 bool swift::RefCounts<swift::RefCountBitsT<(swift::RefCountInlinedness)1>>::doDecrementSlow<(swift::PerformDeinit)1>(swift::RefCountBitsT<(swift::RefCountInlinedness)1>, unsigned int) + 136 (RefCount.h:0)
18  SwiftUI                         0x000000018d661f70 closure #1 in ObjectLocation.set(_:transaction:) + 200 (Binding+ObjectLocation.swift:31)
19  SwiftUI                         0x000000018d661ea0 partial apply for closure #1 in ObjectLocation.set(_:transaction:) + 28 (<compiler-generated>:0)
20  SwiftUI                         0x000000018d653c98 specialized closure #1 in withTransaction<A>(_:_:) + 244 (Transaction.swift:243)
21  SwiftUI                         0x000000018d662084 ObjectLocation.set(_:transaction:) + 244 (Binding+ObjectLocation.swift:30)
22  SwiftUI                         0x000000018d36cab4 LocationBox.set(_:transaction:) + 244 (Location.swift:84)
23  SwiftUI                         0x000000018d36cb34 Binding.ScopedLocation.set(_:transaction:) + 56 (Binding.swift:392)
24  SwiftUI                         0x000000018d36cab4 LocationBox.set(_:transaction:) + 244 (Location.swift:84)
25  SwiftUI                         0x000000018d36cb34 Binding.ScopedLocation.set(_:transaction:) + 56 (Binding.swift:392)
26  SwiftUI                         0x000000018d36cab4 LocationBox.set(_:transaction:) + 244 (Location.swift:84)
27  SwiftUI                         0x000000018d36c978 Binding.wrappedValue.setter + 72 (Binding.swift:167)
28  DevToys                         0x00000001022cb83c 0x102264000 + 423996
29  DevToys                         0x00000001022cdc58 0x102264000 + 433240
30  UIKitCore                       0x000000018c7eec10 -[UITextView textInputDidChange:] + 184 (UITextView.m:4635)
31  UIKitCore                       0x000000018c7d0138 -[UITextInputController _sendDelegateChangeNotificationsForText:selection:] + 152 (UITextInputController.m:438)
32  UIKit                           0x00000002262c6b2c -[UITextInputControllerAccessibility _sendDelegateChangeNotificationsForText:selection:] + 112 (UITextInputControllerAccessibility.m:52)
33  UIKitCore                       0x000000018c7d0ae0 -[UITextInputController _insertText:fromKeyboard:] + 768 (UITextInputController.m:986)
34  UIKitCore                       0x000000018c7d17b0 -[UITextInputController insertText:] + 460 (UITextInputController.m:1156)
35  UIKitCore                       0x000000018c7ec27c -[UITextView insertText:] + 60 (UITextView.m:3660)
36  UIKitCore                       0x000000018c0ff4c8 -[UIKBInputDelegateManager insertText:updateInputSource:] + 332 (UIKBInputDelegateManager.m:0)
37  UIKit                           0x00000002261bc3a8 -[UIKBInputDelegateManagerAccessibility insertText:updateInputSource:] + 112 (UIKBInputDelegateManagerAccessibility.m:63)
38  UIKitCore                       0x000000018c0fa474 -[UIKBInputDelegateManager insertText:] + 92 (UIKBInputDelegateManager.m:680)
39  UIKitCore                       0x000000018c379af8 -[UIKeyboardImpl performKeyboardOutput:checkingDelegate:forwardToRemoteInputSource:] + 4016 (UIKeyboardImpl.m:13008)
40  UIKit                           0x0000000226230224 -[UIKeyboardImplAccessibility performKeyboardOutput:checkingDelegate:forwardToRemoteInputSource:] + 160 (UIKeyboardImplAccessibility.m:444)
41  UIKitCore                       0x000000018c37881c -[UIKeyboardImpl performKeyboardOutput:forwardToRemoteInputSource:] + 32 (UIKeyboardImpl.m:12760)
42  UIKitCore                       0x000000018c3787d4 -[UIKeyboardImpl performKeyboardOutput:] + 92 (UIKeyboardImpl.m:12755)
43  UIKitCore                       0x000000018c39d8bc -[UIKeyboardImpl _performKeyboardOutput:respectingForwardingDelegate:] + 252 (UIKeyboardImpl.m:24021)
44  UIKitCore                       0x000000018c376d48 __55-[UIKeyboardImpl handleKeyboardInput:executionContext:]_block_invoke.1237 + 188 (UIKeyboardImpl.m:12295)
45  UIKitCore                       0x000000018c35f954 -[UIKeyboardImpl performOperations:withTextInputSource:] + 56 (UIKeyboardImpl.m:3488)
46  UIKitCore                       0x000000018c376aac __55-[UIKeyboardImpl handleKeyboardInput:executionContext:]_block_invoke_2 + 764 (UIKeyboardImpl.m:12292)
47  UIKitCore                       0x000000018bb5f348 -[UIKeyboardTaskEntry execute:] + 208 (UIKeyboardTaskQueue.m:869)
48  UIKitCore                       0x000000018bb5f1dc -[UIKeyboardTaskQueue continueExecutionOnMainThread] + 324 (UIKeyboardTaskQueue.m:447)
49  Foundation                      0x000000018835daa4 __NSThreadPerformPerform + 264 (NSThread.m:1084)
50  CoreFoundation                  0x0000000189453834 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 28 (CFRunLoop.c:1957)
51  CoreFoundation                  0x00000001894537c8 __CFRunLoopDoSource0 + 176 (CFRunLoop.c:2001)
52  CoreFoundation                  0x0000000189451298 __CFRunLoopDoSources0 + 244 (CFRunLoop.c:2038)
53  CoreFoundation                  0x0000000189450484 __CFRunLoopRun + 828 (CFRunLoop.c:2955)
54  CoreFoundation                  0x000000018944fcd8 CFRunLoopRunSpecific + 608 (CFRunLoop.c:3420)
55  GraphicsServices                0x00000001ce3001a8 GSEventRunModal + 164 (GSEvent.c:2196)
56  UIKitCore                       0x000000018ba8890c -[UIApplication _run] + 888 (UIApplication.m:3713)
57  UIKitCore                       0x000000018bb3c9d0 UIApplicationMain + 340 (UIApplication.m:5303)
58  SwiftUI                         0x000000018d640148 closure #1 in KitRendererCommon(_:) + 168 (UIKitApp.swift:51)
59  SwiftUI                         0x000000018d5ec714 runApp<A>(_:) + 152 (UIKitApp.swift:14)
60  SwiftUI                         0x000000018d5f84d0 static App.main() + 132 (App.swift:114)
61  DevToys                         0x0000000102278148 0x102264000 + 82248
62  dyld                            0x00000001acb01e4c start + 2240 (dyldMain.cpp:1298)
kkebo commented 6 months ago

I can reproduce this issue on the Swift Playgrounds.

kkebo commented 6 months ago

Other tools (e.g. JSON <> YAML, HTML, Base64, etc.) don't have this issue. Therefore, it's not CodeEditorView's issue, and it may be Ink's issue.

kkebo commented 6 months ago

This didn't crash.

import Ink
MarkdownParser().html(from: "- a\n  ")
kkebo commented 6 months ago

I was wrong. It crashes.

kkebo commented 6 months ago

Ink is not actively maintained. So I'd like to replace it with something like swift-markdown-ui if the Swift Playgrounds app supports ClangTarget.