Note that there are some explanatory texts on larger screens.

plurals
  1. POMysterious crash with NSString method rangeOfComposedCharacterSequenceAtIndex:
    text
    copied!<p>My app uses several <code>UITextView</code>s, and we are getting a crash report from users that we are unable to reproduce.</p> <p>The crash report doesn’t (seem to) contain any of our code, and crashes with an <code>NSInvalidArgumentException</code> in the <code>NSString</code> method <code>rangeOfComposedCharacterSequenceAtIndex:</code>, which isn't called directly by our code but seems to be called by the frameworks.</p> <p>Here is the crash report:</p> <pre><code>0 CoreFoundation __exceptionPreprocess + 130 1 libobjc.A.dylib objc_exception_throw + 38 2 CoreFoundation -[NSException initWithCoder:] 3 Foundation -[NSString rangeOfComposedCharacterSequenceAtIndex:] + 88 4 UIKit __74-[UITextInputController _validCaretPositionFromCharacterIndex:downstream:]_block_invoke + 328 5 UIFoundation -[NSTextStorage coordinateReading:] + 36 6 UIKit -[UITextInputController _validCaretPositionFromCharacterIndex:downstream:] + 218 7 UIKit __52-[UITextInputController _characterPositionForPoint:]_block_invoke + 1112 8 UIFoundation -[NSLayoutManager(TextLocking) coordinateAccess:] + 46 9 UIKit -[UITextInputController _characterPositionForPoint:] + 224 10 UIKit -[UITextSelection setSelectionWithFirstPoint:secondPoint:] + 56 11 UIKit -[UITextInteractionAssistant(UITextInteractionAssistant_Internal) twoFingerRangedSelectGesture:] + 386 12 UIKit _UIGestureRecognizerSendActions + 196 13 UIKit -[UIGestureRecognizer _updateGestureWithEvent:buttonEvent:] + 1138 14 UIKit ___UIGestureRecognizerUpdate_block_invoke + 48 15 UIKit _UIGestureRecognizerRemoveObjectsFromArrayAndApplyBlocks + 218 16 UIKit _UIGestureRecognizerUpdate + 282 17 CoreFoundation __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 20 18 CoreFoundation __CFRunLoopDoObservers + 284 19 CoreFoundation __CFRunLoopRun + 730 20 CoreFoundation CFRunLoopRunSpecific + 522 21 CoreFoundation CFRunLoopRunInMode + 106 22 GraphicsServices GSEventRunModal + 138 23 UIKit UIApplicationMain + 1136 24 main.m line 16 25 libdyld.dylib start + 2 </code></pre> <p>( <a href="https://gist.github.com/timarnold/6981caa6a1ee2b98c2fe" rel="noreferrer">https://gist.github.com/timarnold/6981caa6a1ee2b98c2fe</a> )</p> <p>Since I don’t know exactly what part of our code is causing the crash, I’m not sure what sample code would be helpful to post. I’m more interested in hearing if anyone has seen anything like this, or might have a suggestion about where or how to investigate this further.</p> <h1>Update on 2013-11-21</h1> <p>I was able to reproduce this issue by doing the following:</p> <ul> <li>Add some text to my <code>UITextView</code>, including a trailing newline character (<code>\n</code>)</li> <li>Get my app to force the <code>UITextView</code> to resign first responder status</li> <li>Get my app to assign first responder status to my <code>UITextView</code>, and then tap to insert the cursor at the end of the string (around the location of the newline character)</li> </ul> <p>after which the app crashed with the above report.</p> <p>I attempted to create this in an empty Xcode project with just a stock <code>UITextView</code> and nothing else, and was unable to do so. It seems as though there's something going on in my app that conspires with <code>UITextView</code> to make this crash occur. Would love to know what, but the issue is solved for me in this project (as we are not interested in trailing newline characters, and can trim them, thus keeping crashes from occurring).</p> <p>If someone can reproduce this in a sample project, would be great to file a radar if this is indeed a bug with <code>UITextView</code>.</p> <p>Thanks to @wattson12 and @Johan Kool for responses leading to a solution.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload