louisdh / openterm

OpenTerm, a sandboxed command line interface for iOS
Other
1.63k stars 249 forks source link

Crash with Scripts library view #122

Closed alessaba closed 6 years ago

alessaba commented 6 years ago

Steps to reproduce:

  1. Open the scripts view
  2. Open a script
  3. Press on the book icon
  4. Interact with the view
  5. Go back to the terminal view

image

alessaba commented 6 years ago

I don’t know what changed but now the reproducibility went from 100% to about 30%

louisdh commented 6 years ago

I haven't been able to reproduce this, not even once 😕. But I have gotten a bunch of crash reports about an internal exception from UIDocument:

Last Exception Backtrace:
0   CoreFoundation                  0x183ba6d8c __exceptionPreprocess + 228 (NSException.m:166)
1   libobjc.A.dylib                 0x182d605ec objc_exception_throw + 56 (objc-exception.mm:521)
2   CoreFoundation                  0x183ba6bf8 +[NSException raise:format:arguments:] + 104 (NSException.m:132)
3   Foundation                      0x184596fa0 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 112 (NSException.m:157)
4   UIKit                           0x18e8ffe70 -[UIDocument openWithCompletionHandler:] + 704 (UIDocument.m:655)
5   UIKit                           0x18e9023e4 -[UIDocument revertToContentsOfURL:completionHandler:] + 340 (UIDocument.m:1091)
6   UIKit                           0x18e908708 __46-[UIDocument relinquishPresentedItemToWriter:]_block_invoke.769 + 868 (UIDocument.m:2058)
7   libdispatch.dylib               0x183498ae4 _dispatch_client_callout + 16 (object.m:507)
8   libdispatch.dylib               0x1834db3d8 _dispatch_sync_thread_bound_invoke + 68 (queue.c:4055)
9   libdispatch.dylib               0x183498ae4 _dispatch_client_callout + 16 (object.m:507)
10  libdispatch.dylib               0x1834d9d60 _dispatch_main_queue_callback_4CF$VARIANT$armv81 + 964 (inline_internal.h:2500)
11  CoreFoundation                  0x183b4f070 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 12 (CFRunLoop.c:1815)
12  CoreFoundation                  0x183b4cbc8 __CFRunLoopRun + 2272 (CFRunLoop.c:3111)
13  CoreFoundation                  0x183a6cda8 CFRunLoopRunSpecific + 552 (CFRunLoop.c:3245)
14  GraphicsServices                0x185a50020 GSEventRunModal + 100 (GSEvent.c:2245)
15  UIKit                           0x18e237afc UIApplicationMain + 236 (UIApplication.m:3965)
16  OpenTerm                        0x104f73f40 main + 56 (AppDelegate.swift:17)
17  libdyld.dylib                   0x1834fdfc0 start + 4

I don't think the "book icon" view has any effect on the crash. From the crash log it appears there's something wrong with ScriptEditViewController, more specifically the document property it has (of type PridelandDocument).

It would be extremely helpful if you found a way for me to reproduce this. For example: can you ever reproduce this when installed from Xcode, or only from TestFlight?

alessaba commented 6 years ago

Tomorrow i'll try the Xcode version, but in the meantime i found another way to trigger the bug: tap on a script, swiping up from about the middle of the view , then press back two times to back to the terminal. It will crash

Filippo Claudi

Il giorno 23 apr 2018, alle ore 21:17, louisdh notifications@github.com ha scritto:

I haven't been able to reproduce this, not even once 😕. But I have gotten a bunch of crash reports about an internal exception from UIDocument:

Last Exception Backtrace: 0 CoreFoundation 0x183ba6d8c exceptionPreprocess + 228 (NSException.m:166) 1 libobjc.A.dylib 0x182d605ec objc_exception_throw + 56 (objc-exception.mm:521) 2 CoreFoundation 0x183ba6bf8 +[NSException raise:format:arguments:] + 104 (NSException.m:132) 3 Foundation 0x184596fa0 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 112 (NSException.m:157) 4 UIKit 0x18e8ffe70 -[UIDocument openWithCompletionHandler:] + 704 (UIDocument.m:655) 5 UIKit 0x18e9023e4 -[UIDocument revertToContentsOfURL:completionHandler:] + 340 (UIDocument.m:1091) 6 UIKit 0x18e908708 46-[UIDocument relinquishPresentedItemToWriter:]_block_invoke.769 + 868 (UIDocument.m:2058) 7 libdispatch.dylib 0x183498ae4 _dispatch_client_callout + 16 (object.m:507) 8 libdispatch.dylib 0x1834db3d8 _dispatch_sync_thread_bound_invoke + 68 (queue.c:4055) 9 libdispatch.dylib 0x183498ae4 _dispatch_client_callout + 16 (object.m:507) 10 libdispatch.dylib 0x1834d9d60 _dispatch_main_queue_callback_4CF$VARIANT$armv81 + 964 (inline_internal.h:2500) 11 CoreFoundation 0x183b4f070 CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE + 12 (CFRunLoop.c:1815) 12 CoreFoundation 0x183b4cbc8 __CFRunLoopRun + 2272 (CFRunLoop.c:3111) 13 CoreFoundation 0x183a6cda8 CFRunLoopRunSpecific + 552 (CFRunLoop.c:3245) 14 GraphicsServices 0x185a50020 GSEventRunModal + 100 (GSEvent.c:2245) 15 UIKit 0x18e237afc UIApplicationMain + 236 (UIApplication.m:3965) 16 OpenTerm 0x104f73f40 main + 56 (AppDelegate.swift:17) 17 libdyld.dylib 0x1834fdfc0 start + 4 I don't think the "book icon" view has any effect on the crash. From the crash log it appears there's something wrong with ScriptEditViewController, more specifically the document property it has (of type PridelandDocument).

It would be extremely helpful if you found a way for me to reproduce this. For example: can you ever reproduce this when installed from Xcode, or only from TestFlight?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.

alessaba commented 6 years ago

Update: i can even trigger it by repeatedly opening and closing a script 😨 image

louisdh commented 6 years ago

Hmm, so the documentation panel definitely has nothing to do with the crash. Can you reproduce it while attached to Xcode's debugger?

alessaba commented 6 years ago

ok so it's been almost an hour and I can't get it to crash when using the Xcode built version. the only thing I see now when I do the same steps is this

2018-04-24 21:02:20.351189+0200 OpenTerm[6584:2808414] [LayoutConstraints] Unable to simultaneously satisfy constraints. Probably at least one of the constraints in the following list is one you don't want. Try this: (1) look at each constraint and try to figure out which you don't expect; (2) find the code that added the unwanted constraint or constraints and fix it. (Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints) ( "<NSAutoresizingMaskLayoutConstraint:0x1c8280370 h=--& v=--& UIKeyboardAssistantBar:0x137d090d0.height == 0 (active)>", "<NSLayoutConstraint:0x1c8085870 V:|-(0)-[_UIButtonBarStackView:0x137d09660] (active, names: '|':UIKeyboardAssistantBar:0x137d090d0 )>", "<NSLayoutConstraint:0x1c80858c0 V:[_UIButtonBarStackView:0x137d09660]-(0)-| (active, names: '|':UIKeyboardAssistantBar:0x137d090d0 )>", "<NSLayoutConstraint:0x1c409ce80 'UISV-canvas-connection' UILayoutGuide:0x1c81a62e0'UIViewLayoutMarginsGuide'.top == _UILayoutSpacer:0x1c41c8ca0'UISV-alignment-spanner'.top (active)>", "<NSLayoutConstraint:0x1c4093970 'UISV-canvas-connection' UILayoutGuide:0x1c81a62e0'UIViewLayoutMarginsGuide'.bottom == _UILayoutSpacer:0x1c41c8ca0'UISV-alignment-spanner'.bottom (active)>", "<NSLayoutConstraint:0x1c8084dd0 'UIView-bottomMargin-guide-constraint' V:[UILayoutGuide:0x1c81a62e0'UIViewLayoutMarginsGuide']-(9)-| (active, names: '|':_UIButtonBarStackView:0x137d09660 )>", "<NSLayoutConstraint:0x1c8084d30 'UIView-topMargin-guide-constraint' V:|-(10)-[UILayoutGuide:0x1c81a62e0'UIViewLayoutMarginsGuide'] (active, names: '|':_UIButtonBarStackView:0x137d09660 )>" )

Will attempt to recover by breaking constraint <NSLayoutConstraint:0x1c4093970 'UISV-canvas-connection' UILayoutGuide:0x1c81a62e0'UIViewLayoutMarginsGuide'.bottom == _UILayoutSpacer:0x1c41c8ca0'UISV-alignment-spanner'.bottom (active)>

Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger. The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful. 2018-04-24 21:02:20.355160+0200 OpenTerm[6584:2808414] [LayoutConstraints] Unable to simultaneously satisfy constraints. Probably at least one of the constraints in the following list is one you don't want. Try this: (1) look at each constraint and try to figure out which you don't expect; (2) find the code that added the unwanted constraint or constraints and fix it. (Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints) ( "<NSAutoresizingMaskLayoutConstraint:0x1c8280370 h=--& v=--& UIKeyboardAssistantBar:0x137d090d0.height == 0 (active)>", "<NSLayoutConstraint:0x1c8085870 V:|-(0)-[_UIButtonBarStackView:0x137d09660] (active, names: '|':UIKeyboardAssistantBar:0x137d090d0 )>", "<NSLayoutConstraint:0x1c80858c0 V:[_UIButtonBarStackView:0x137d09660]-(0)-| (active, names: '|':UIKeyboardAssistantBar:0x137d090d0 )>", "<NSLayoutConstraint:0x1c409ce80 'UISV-canvas-connection' UILayoutGuide:0x1c81a62e0'UIViewLayoutMarginsGuide'.top == _UILayoutSpacer:0x1c41c8ca0'UISV-alignment-spanner'.top (active)>", "<NSLayoutConstraint:0x1c8084e70 'UISV-canvas-connection' UILayoutGuide:0x1c81a62e0'UIViewLayoutMarginsGuide'.centerY == _UILayoutSpacer:0x1c41c8ca0'UISV-alignment-spanner'.centerY (active)>", "<NSLayoutConstraint:0x1c8084dd0 'UIView-bottomMargin-guide-constraint' V:[UILayoutGuide:0x1c81a62e0'UIViewLayoutMarginsGuide']-(9)-| (active, names: '|':_UIButtonBarStackView:0x137d09660 )>", "<NSLayoutConstraint:0x1c8084d30 'UIView-topMargin-guide-constraint' V:|-(10)-[UILayoutGuide:0x1c81a62e0'UIViewLayoutMarginsGuide'] (active, names: '|':_UIButtonBarStackView:0x137d09660 )>" )

Will attempt to recover by breaking constraint <NSLayoutConstraint:0x1c8084e70 'UISV-canvas-connection' UILayoutGuide:0x1c81a62e0'UIViewLayoutMarginsGuide'.centerY == _UILayoutSpacer:0x1c41c8ca0'UISV-alignment-spanner'.centerY (active)>

Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger. The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful. 2018-04-24 21:02:20.356176+0200 OpenTerm[6584:2808414] [LayoutConstraints] Unable to simultaneously satisfy constraints. Probably at least one of the constraints in the following list is one you don't want. Try this: (1) look at each constraint and try to figure out which you don't expect; (2) find the code that added the unwanted constraint or constraints and fix it. (Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints) ( "<NSAutoresizingMaskLayoutConstraint:0x1c8280370 h=--& v=--& UIKeyboardAssistantBar:0x137d090d0.height == 0 (active)>", "<NSLayoutConstraint:0x1c8085910 V:|-(0)-[_UIButtonBarStackView:0x137d09f90] (active, names: '|':UIKeyboardAssistantBar:0x137d090d0 )>", "<NSLayoutConstraint:0x1c8085960 V:[_UIButtonBarStackView:0x137d09f90]-(0)-| (active, names: '|':UIKeyboardAssistantBar:0x137d090d0 )>", "<NSLayoutConstraint:0x1c4094cd0 'UIButtonBar.maximumAlignmentSize' UIView:0x137d0a5b0.height == UILayoutGuide:0x1c81a6660'UIViewLayoutMarginsGuide'.height (active)>", "<NSLayoutConstraint:0x1c80850f0 'UIView-bottomMargin-guide-constraint' V:[UILayoutGuide:0x1c81a6660'UIViewLayoutMarginsGuide']-(9)-| (active, names: '|':_UIButtonBarStackView:0x137d09f90 )>", "<NSLayoutConstraint:0x1c8085050 'UIView-topMargin-guide-constraint' V:|-(10)-[UILayoutGuide:0x1c81a6660'UIViewLayoutMarginsGuide'] (active, names: '|':_UIButtonBarStackView:0x137d09f90 )>" )

Will attempt to recover by breaking constraint <NSLayoutConstraint:0x1c80850f0 'UIView-bottomMargin-guide-constraint' V:[UILayoutGuide:0x1c81a6660'UIViewLayoutMarginsGuide']-(9)-| (active, names: '|':_UIButtonBarStackView:0x137d09f90 )>

Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.

barrettj commented 6 years ago

Is it possible that you’re opening a uidocument instance before a different instance of the uidocument is done closing?

alessaba commented 6 years ago

That's definitely possible, because it almost 100% works when opening and reclosing scripts very fast. the strange thing is it is not always the case.

Maybe the crash is changing view before the document has finished saving. From the 2 gifs I posted you can see it crashes both coming back to the terminal view and script editor view.

louisdh commented 6 years ago

@barrettj That's possible, but even if I comment out the document closing (so documents never close) and I open the same document multiple times, I don't get the crash. Also not sure how to guard against that, should we block the UI while a document is closing?

barrettj commented 6 years ago

I believe that wouldnt catch the issue. I think what occurs is when you open the second and the original goes to close and save it finds the file open and says it needs to revert the document instead of saving.

That’s my best guess based on having similar uidocument issues in my own app.

louisdh commented 6 years ago

Progress: I've been able to reproduce it while Xcode's debugger is attached.

LeoNatan commented 6 years ago

What is the exception?

louisdh commented 6 years ago

@LeoNatan It's just an NSException, caused by UIDocument openWithCompletionHandler

louisdh commented 6 years ago

I think this crash is fixed by disabling document reverting: 334ca59179bd7b8c40b02b7ff58c116b11a6ffda. Will create a new TestFlight build and see if the crash persists.

LeoNatan commented 6 years ago

I meant, what was the exception reason?

louisdh commented 6 years ago

@LeoNatan Not sure what you mean by "exception reason", you mean what caused the crash? See this commit for the fix: 334ca59179bd7b8c40b02b7ff58c116b11a6ffda

LeoNatan commented 6 years ago

I meant this: https://developer.apple.com/documentation/foundation/nsexception/1415537-reason

Every exception has an informative string with it, explaining the reason. I am not sure how you are catching the exceptions in productions, but it is a good idea to include the reason and exception name in the report.

louisdh commented 6 years ago

I am using the default crash logs from Apple, available in Xcode's "Organizer". I don't think those include the exception reason, due to privacy concerns.