TextExpander / TextExpanderTouchSDK

TextExpander touch SDK
85 stars 13 forks source link

iOS 8: Crash when using textView:shouldChangeTextInRange:replacementText: #8

Closed bdolman closed 9 years ago

bdolman commented 10 years ago

SDK Version: 2.3.1

I have a TextExpander-enabled text view that's using -[UITextView textView:shouldChangeTextInRange:replacementText:] to replace text in this manner:

- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
{
    textView.text = [textView.text stringByAppendingString:@"Z"];
    return NO;
}

Which results in this exception:

*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'enableUndoRegistration: _UITextUndoManager 0x7f9b40d31880 is in invalid state, enableUndoRegistration may only be invoked with matching call to disableUndoRegistration
'
*** First throw call stack:
(
    0   CoreFoundation                      0x000000010778c3e5 __exceptionPreprocess + 165
    1   libobjc.A.dylib                     0x000000010743a967 objc_exception_throw + 45
    2   CoreFoundation                      0x000000010778c31d +[NSException raise:format:] + 205
    3   Foundation                          0x0000000107021d07 -[NSUndoManager enableUndoRegistration] + 128
    4   TextExpanderBug                     0x000000010686b9f7 -[SMTEDelegateController textView:shouldChangeTextInRange:replacementText:] + 4242
    5   UIKit                               0x00000001086c2fdd -[UITextView keyboardInput:shouldInsertText:isMarkedText:] + 105
    6   UIKit                               0x00000001081a20aa -[UIKeyboardImpl callShouldInsertText:] + 109
    7   UIKit                               0x00000001081abad3 -[UIKeyboardImpl addInputEvent:executionContext:] + 872
    8   UIKit                               0x00000001081ab6e9 __60-[UIKeyboardImpl addInputString:withFlags:executionContext:]_block_invoke + 36
    9   UIKit                               0x00000001087084c9 -[UIKeyboardTaskExecutionContext returnExecutionToParentWithInfo:] + 264
    10  UIKit                               0x00000001081af9e3 -[UIKeyboardImpl acceptCurrentCandidateIfSelectedWithExecutionContext:] + 224
    11  UIKit                               0x00000001081ab6b6 -[UIKeyboardImpl addInputString:withFlags:executionContext:] + 507
    12  UIKit                               0x00000001081b921c -[UIKeyboardImpl handleKeyWithString:forKeyEvent:executionContext:] + 513
    13  UIKit                               0x00000001081b8ea0 -[UIKeyboardImpl handleKeyEvent:executionContext:] + 1573
    14  UIKit                               0x0000000108708974 -[UIKeyboardTaskQueue continueExecutionOnMainThread] + 332
    15  UIKit                               0x00000001081b87db -[UIKeyboardImpl handleKeyEvent:] + 216
    16  UIKit                               0x0000000107fd5518 _UIApplicationHandleEventFromQueueEvent + 2469
    17  UIKit                               0x0000000107fb4679 _UIApplicationHandleEventQueue + 1967
    18  CoreFoundation                      0x00000001076c1ac1 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
    19  CoreFoundation                      0x00000001076b798d __CFRunLoopDoSources0 + 269
    20  CoreFoundation                      0x00000001076b6fc4 __CFRunLoopRun + 868
    21  CoreFoundation                      0x00000001076b69f6 CFRunLoopRunSpecific + 470
    22  GraphicsServices                    0x000000010a7d19f0 GSEventRunModal + 161
    23  UIKit                               0x0000000107fb7990 UIApplicationMain + 1282
    24  TextExpanderBug                     0x0000000106865253 main + 115
    25  libdyld.dylib                       0x000000010a2e3145 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException

I can workaround this by disabling undo support using provideUndoSupport = NO.

This bug does not manifest itself on iOS 7.

gscown commented 10 years ago

Thanks for reporting this. We are testing a fix, which we hope to make available shortly.

bdolman commented 10 years ago

Great, thank you for attending to it. On Aug 30, 2014, at 2:28 PM, gscown notifications@github.com wrote:

Thanks for reporting this. We are testing a fix, which we hope to make available shortly.

— Reply to this email directly or view it on GitHub.

gscown commented 10 years ago

Here is a release candidate of the 3.0 SDK with this fix:

http://smilesoftware.com/downloads/test/teTouchSDK_3.0b3.zip

We expect to push to GitHub later this week. We'd certainly welcome feedback as to whether this works for you. We do have confirmed feedback from another developer that this resolves the issue, but we certainly welcome the additional confirmation.

bdolman commented 10 years ago

Yep, beta build fixes it. Looking forward to the official release this week!

rmaddy commented 10 years ago

I just updated to the latest framework moments ago and I now see this same problem. When will this update become available? Thanks.

gscown commented 10 years ago

Hi @rmaddy. I just cloned master of the TextExpanderTouchSDK project and replaced the call to textView:shouldChangeTextInRange: in SMFirstViewController in TextExpanderDemoApp with @bdolman's line above then ran successfully on iOS 8. The calls to the undo manager which originate from the TextExpander touch SDK when provideUndoSupport is true (as is the default) are balanced. If you can take me through a reproducible case using TextExpanderDemoApp, that would be very helpful. You might also double-check that your framework was indeed updated. Maybe you just need to do a clean build after having replaced it.

rmaddy commented 10 years ago

I've done two clean builds - the 2nd being after doing a clean clone of master. Still seeing the problem under iOS 8. I'll see if I can put together a simple demo. Thanks.

rmaddy commented 10 years ago

@gscown I found that the problem is only happening in cases where I am already doing my own "undo" support for a UITextField. I solved the problem by using provideUndoSupport = NO; on the SMTEDelegateController. The crash was not happening on another UITextField that didn't have my own undo support.

Nowhere in my code was I calling NSUndoManager disableUndoRegistration so there seems to be a mismatched call to enableUndoRegistration in your library. My code is calling prepareWithInvocationTarget: and setActionName: on my local NSUndoManager each time the text field is changed.

guidedways commented 10 years ago

I'm seeing this with the latest TextExpander SDK and iOS 8, for fields that aren't using an Undo Manager.

youens commented 9 years ago

I have this problem in iOS 8.0 and TextExpander 3.0.2 when I'm already using an undo manager. Setting the delegate's provideUndoSupport property to NO resolves my issue.

gscown commented 9 years ago

I believe we've resolved the last instance of this in the 3.0.3 SDK, which you'll find here. If you're still able to reproduce with the demo app and the 3.0.3 SDK, please send us details: http://smle.us/support

youens commented 9 years ago

Ah, very well could be. I attempted to update CocoaPods first, but I guess it didn't grab it. Thanks!