NSRangeException on iOS 8 - ios

I upgraded XCode 5 to 6 to test my projects out on the iPhone 6 and 6 Plus and was getting cryptic crashes on startup:
'*** -[__NSArrayM objectAtIndex:]: index 4 beyond bounds [0 .. 3]'
*** First throw call stack:
(
0 CoreFoundation 0x000000010569b3f5 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x0000000104b20bb7 objc_exception_throw + 45
2 CoreFoundation 0x00000001055864d3 -[__NSArrayM objectAtIndex:] + 227
3 UIKit 0x00000001028164e1 _UIViewTopDownSubtreeTraversal + 193
4 UIKit 0x0000000102e43286 -[UIView(UIConstraintBasedLayout_EngineDelegate) _invalidateSystemLayoutSizeFittingSizeAtEngineDelegateLevel] + 128
5 Foundation 0x0000000103aa66df -[NSISEngine tryToAddConstraintWithMarker:expression:integralizationAdjustment:mutuallyExclusiveConstraints:] + 915
6 Foundation 0x0000000103c2f678 -[NSLayoutConstraint _addLoweredExpression:toEngine:integralizationAdjustment:lastLoweredConstantWasRounded:mutuallyExclusiveConstraints:] + 275
7 Foundation 0x0000000103a9ae3a -[NSLayoutConstraint _addToEngine:integralizationAdjustment:mutuallyExclusiveConstraints:] + 220
8 UIKit 0x0000000102e40495 __57-[UIView(AdditionalLayoutSupport) _switchToLayoutEngine:]_block_invoke_2 + 474
9 Foundation 0x0000000103aa8a8e -[NSISEngine withBehaviors:performModifications:] + 155
10 UIKit 0x0000000102e4029b __57-[UIView(AdditionalLayoutSupport)
After a LOT of trial and error and trying various XIBs in various configurations, the issue occurred because I was mixing some XIBs with Auto Layout turned on, containing other UIViews (based on XIBs) with AutoLayout off.
Turning AutoLayout off for all of my XIBs solved the issue.

Faced the same issue. Found that the problem is in button whose layer was used as mask for another button's layer for some visual effect (CALayer's mask property). Removing mask button from view hierarchy fixed the problem. I just moved it to view controller scene in storyboard.
Looks like using layer as a mask caused problem in _UIViewTopDownSubtreeTraversal function used by autolayout. Maybe other layer manipulations for some view also can.

One solution I found is that you need to have at least 6 screens and then the app won't crash.
Still trying to get it to work with less screens.
Turned off Auto Layout on my only XIB (LaunchScreen.xib) but that didn't solve the problem.

Related

App crashing on runTransitionForCurrentState but no clue as to why

I've tried searching for this, but no luck, so hoping there are some guru's who may know the answer.
I'm seeing loads of reports in iTunes Connect of my app crashing with a particular stack trace, but the stack trace reveals nothing useful.
#0. Crashed: main
0 UIKit 0x1871100c0 __56-[UIPresentationController runTransitionForCurrentState]_block_invoke + 324
1 UIKit 0x1871100bc __56-[UIPresentationController runTransitionForCurrentState]_block_invoke + 320
2 UIKit 0x1870630c8 _runAfterCACommitDeferredBlocks + 292
3 UIKit 0x187070a80 _cleanUpAfterCAFlushAndRunDeferredBlocks + 92
4 UIKit 0x186da25a4 _afterCACommitHandler + 96
5 CoreFoundation 0x181c0c728 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 32
6 CoreFoundation 0x181c0a4cc __CFRunLoopDoObservers + 372
7 CoreFoundation 0x181c0a8fc __CFRunLoopRun + 928
8 CoreFoundation 0x181b34c50 CFRunLoopRunSpecific + 384
9 GraphicsServices 0x18341c088 GSEventRunModal + 180
10 UIKit 0x186e1a088 UIApplicationMain + 204
11 MyApp 0x100082e6c main (main.m:19)
12 libdyld.dylib 0x1816d28b8 start + 4
No pattern to the reports, happens on iOS 9.1, 9.2, 9.3-10 and various iPhones and iPads and no clues to help reproduce it.
Has anyone experienced something like this before and have some insight/suspicion on what may cause it?
I have the exact same crash, and I've figured out the cause. A highly-reduced version of my code looks something like
[self dismissViewControllerAnimated:YES completion:nil];
// call a method that ends up doing
[appRootViewController dismissViewControllerAnimated:NO completion:nil];
self in the above snippet is a view controller that's been presented modally over the root. The view controller itself has also presented modally over current context some other controller. So what I'm doing is trying to dismiss that over-current-context controller with animation, then calling other code that ultimately dismisses any presented view controller from the root without animation.
Or to put it another way, the view controller providing the current context for an animated dismiss that I just kicked off gets removed from the view hierarchy while the previous animated dismissal is in progress.
When reproducing this in Xcode, it also logs the following to the console:
transitionViewForCurrentTransition is not set, presentation controller was dismissed during the presentation? (<_UIOverCurrentContextPresentationController: 0x7faf277d9c30>)

Auto-Layout crash on iOS 9 with auto-layout disabled

I know this is a generic question, but I hope that someone who had a similar experience may have an idea of what's probably happening.
I'm getting a crash that occurs only on iOS 9 in our iPad-only app. It says NSInternalInconsistencyException.
It occurs on both Portrait and Landscape modes, and on many iPad generations (iPad 2, iPad Pro, iPad 4, ...).
I don't have Auto Layout enabled anywhere in the project, yet it looks like an auto layout issue.
It's very hard to replicate, so I'm not able to debug it on Xcode, but I'm seeing reports on the crash analytics service "Crashlytics". Here's the stack trace from Crashlytics:
Auto layout internal error. Cannot find an outgoing row
head for incoming head <unknown var (bug!) with engine as delegate[...]
Thread : Fatal Exception: NSInternalInconsistencyException
0 CoreFoundation 0x23d4568b __exceptionPreprocess
1 libobjc.A.dylib 0x356c2e17 objc_exception_throw
2 CoreFoundation 0x23d455d1 -[NSException initWithCoder:]
3 Foundation 0x24a873b3 -[NSISEngine minimizeConstantInObjectiveRowWithHead:]
4 Foundation 0x24a86e4d -[NSISEngine optimize]
5 Foundation 0x24a82a53 -[NSISEngine withBehaviors:performModifications:]
6 UIKit 0x27e040bb -[UIView(Hierarchy) _postMovedFromSuperview:]
7 UIKit 0x280fb227 __UIViewWasRemovedFromSuperview
8 UIKit 0x27e02ddb -[UIView(Hierarchy) removeFromSuperview]
9 UIKit 0x282e5fa9 -[UIKeyboardPredictionView setPredictionViewState:animate:notify:]
10 UIKit 0x281e3787 -[UIKeyboardImpl updatePredictionView]
11 UIKit 0x27f155e3 -[UIKeyboardImpl finishLayoutChangeWithArguments:]
12 UIKit 0x27e31437 -[UIKeyboardImpl updateLayout]
13 UIKit 0x27e36077 -[UIKeyboardImpl setDelegate:force:]
14 UIKit 0x27e2f6e1 -[UIPeripheralHost(UIKitInternal) _reloadInputViewsForResponder:]
15 UIKit 0x27e2f20d -[UIResponder(UIResponderInputViewAdditions) reloadInputViews]
16 UIKit 0x27e8d853 -[UIResponder becomeFirstResponder]
17 UIKit 0x27e8db6d -[UIView(Hierarchy) becomeFirstResponder]
18 UIKit 0x27f12289 -[UITextField becomeFirstResponder]
19 UIKit 0x27fbe69f -[UITextInteractionAssistant(UITextInteractionAssistant_Internal) setFirstResponderIfNecessary]
20 UIKit 0x27fbdc75 -[UITextInteractionAssistant(UITextInteractionAssistant_Internal) oneFingerTap:]
21 UIKit 0x28334e27 _UIGestureRecognizerSendTargetActions
22 UIKit 0x27fa2303 _UIGestureRecognizerSendActions
23 UIKit 0x27e3a7af -[UIGestureRecognizer _updateGestureWithEvent:buttonEvent:]
24 UIKit 0x28335f2f ___UIGestureRecognizerUpdate_block_invoke809
25 UIKit 0x27dfc287 _UIGestureRecognizerRemoveObjectsFromArrayAndApplyBlocks
26 UIKit 0x27df9e77 _UIGestureRecognizerUpdate
27 UIKit 0x27e386f9 -[UIWindow _sendGesturesForEvent:]
28 UIKit 0x27e37e43 -[UIWindow sendEvent:]
29 UIKit 0x27e097e5 -[UIApplication sendEvent:]
30 UIKit 0x27e07fdf _UIApplicationHandleEventQueue
31 CoreFoundation 0x23d08c3f __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__
32 CoreFoundation 0x23d0882d __CFRunLoopDoSources0
33 CoreFoundation 0x23d06b9b __CFRunLoopRun
34 CoreFoundation 0x23c5a249 CFRunLoopRunSpecific
35 CoreFoundation 0x23c5a035 CFRunLoopRunInMode
36 GraphicsServices 0x2cd24ad1 GSEventRunModal
37 UIKit 0x27e6f899 UIApplicationMain
38 Mr Appliance 0xcda7b main (main.m:16)
39 libdyld.dylib 0x35e0e873 start
The problem is that I don't know where in the code this is happening. The stack trace doesn't show where in the code the crash is occurring. It only says main.m line 16 which is return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));.
That line in main.m is where your program starts running, not where the error happens. The exception is thrown at #1 the top of the list after all the other items have happened. The problem lies somewhere in between.
After some view is removed from its superview there's an exception, and it does show NSISEngine errors indicating that perhaps AutoLayout is turned on for some XIB or Storyboard - or else iOS is using AutoLayout internally to handle the arrangement of the new layout.
This answer has a nearly identical stack trace & points to the issue being with using incorrect gesture methods to handle firstResponder changes and dismiss a keyboard. If you're doing something similar (dismissing some view, editing a UITableView?) maybe it's with the wrong method pointing to a delegate that doesn't exist?
https://stackoverflow.com/questions/33800918/uitextfield-becomefirstresponder-crashes-the-ios-app-randomly
The stacktrace indicates an issue regarding the onscreen keyboard. There is a layout change that ends up with a non exsistant delegate. Looks like your code triggers direct or indirect a layoutchange related to the keyboard.
Thing is, a keyboard on the screen is not grated even when your app does recive input.
As for the iPad Pro and the Smart Keyboard you may have a quicktype bar and that can be hidden too. Quite some apps have issues with external keyboards.
Try connecting a bluetooth keyboard to one of your test device. Connect it to xcode, set a breakpoint on exeptions and try your textfields. Guess you will find what you are looking for.
May be you might have misspelled any viewcontroller or xib name while initiating it or may be you have changed, name of the file, or moved it, in physical folder and forget to remove it from xcode.

App crashes on Users device in UIViewController: com.apple.main-thread

i use fabric.io to track the crashes on the devices of users. I get many crash reports with following stack trace:
0 libobjc.A.dylib 0x33e9ef46 objc_msgSend + 5
1 UIKit 0x29698225 +[UIViewController _viewControllerForFullScreenPresentationFromView:] + 196
2 UIKit 0x29697cfb -[UIWindow _scrollToTopViewsUnderScreenPointIfNecessary:resultHandler:] + 442
3 UIKit 0x29697b1f -[_UIScrollsToTopInitiatorView touchesEnded:withEvent:] + 214
4 UIKit 0x29697a41 -[UIStatusBar touchesEnded:withEvent:] + 416
5 UIKit 0x295fc245 forwardTouchMethod + 236
6 UIKit 0x294ae567 -[UIWindow _sendTouchesForEvent:] + 522
7 UIKit 0x294a7e31 -[UIWindow sendEvent:] + 544
8 UIKit 0x2947e759 -[UIApplication sendEvent:] + 196
9 UIKit 0x296f22f9 _UIApplicationHandleEventFromQueueEvent + 14168
10 UIKit 0x2947d1a9 _UIApplicationHandleEventQueue + 1352
11 CoreFoundation 0x25f27fbf __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 14
12 CoreFoundation 0x25f273cf __CFRunLoopDoSources0 + 218
13 CoreFoundation 0x25f25a35 __CFRunLoopRun + 772
14 CoreFoundation 0x25e733b1 CFRunLoopRunSpecific + 476
15 CoreFoundation 0x25e731c3 CFRunLoopRunInMode + 106
16 GraphicsServices 0x2d3d3201 GSEventRunModal + 136
17 UIKit 0x294dd43d UIApplicationMain + 1440
So in the whole stack trace, there is not a single line of my code. I cannot think of any reason why this happens.
Does anybody have the same problem or an idea how to approach this problem?
Thanks in advance
I've encountered a similar problem and the crash report I got is almost the same as yours.
You crash must be the case that app crashes when users tap on the status bar to scroll to top in a UIScrollView. This is exactly what I encountered.
The root cause is that I call [UIScrollView setContentOffset:] before viewDidAppear gets called.
Somehow if you call UIScrollView setContentOffset prior to view controller appearance, iOS system will try to retain your UIScrollView instance after it is deallocated, resulting in SIGEV or SIGBUS.
If you debug your app with Enable Zombie Objects, you will surely get something similar to
[UIScrollView retain]: message sent to deallocated instance
0x1371a7600
.
If you would like to reproduce the crash, I suggest that you do the following.
Create two view controllers, both with UIScrollView instance added to view hierarchy.
Push them to navigation stack and be sure to call setContentOffset in viewDidLoad and before viewDidAppear for both of them.
Pop one view controller and leave the other in navigation stack
Tap status bar.
The solution is that you should check if view controller's view.window property is nil or not, if it is nil, do not call setContentOffset of UIScrollView instance, delay all calls to setContentOffset until view.window is non-nil.
I also write a blog post about this.Although my blog is in Chinese, I added a screenshot of the call stack at the time of a crash and you can see that the call stack is the same as the stack of this question.
https://huang.sh/2016/07/%e5%ae%9a%e4%bd%8d%e5%b4%a9%e6%ba%83uikituiviewcontroller-_viewcontrollerforfullscreenpresentationfromview/

iphone app crash at -[UITableView _selectRowAtIndexPath:animated:scrollPosition:notifyDelegate:]

I get crash at -[UITableView _selectRowAtIndexPath:animated:scrollPosition:notifyDelegate:] without any trace refer to our app,could any one tell me what's the problem.
There are about 500 crashes with 99% on the ios7 System.
Thread : Crashed: com.apple.main-thread
0 libobjc.A.dylib 0x397e1b26 objc_msgSend + 5
1 UIKit 0x31c358bb -[UITableView _selectRowAtIndexPath:animated:scrollPosition:notifyDelegate:] + 1078
2 UIKit 0x31ce8f7b -[UITableView _userSelectRowAtPendingSelectionIndexPath:] + 214
3 UIKit 0x31b98fb9 _applyBlockToCFArrayCopiedToStack + 316
4 UIKit 0x31b111f3 _afterCACommitHandler + 430
5 CoreFoundation 0x2f3711cd __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 20
6 CoreFoundation 0x2f36eb71 __CFRunLoopDoObservers + 284
7 CoreFoundation 0x2f36eeb3 __CFRunLoopRun + 730
8 CoreFoundation 0x2f2d9c27 CFRunLoopRunSpecific + 522
9 CoreFoundation 0x2f2d9a0b CFRunLoopRunInMode + 106
10 GraphicsServices 0x34000283 GSEventRunModal + 138
11 UIKit 0x31b7d049 UIApplicationMain + 1136
12 MyApp 0x0004e813 main (main.m:16)
#Umesh Kumar: YES
Finally, it turns out that its the navigation stacks confusion.
Here is the detail:
We all know two or more buttons action can be performed at the same time by default.(exclusiveTouch=NO)
Sometimes, when a button in you controller be taped which will cause the nav to push to next controller, but people may taped the back button on the left of the navbar which will simply pop the controller. This will cause the navigation stacks confusion. You will see the controller pushed in or poped back really strange.
When this happens, there will always be many strange crashes, include the crash I figured above.
Note that, According to my experience, This happens on IOS 7 only, and these crashes only happens on IOS 7 too.
So, we need to set button.exclusiveTouch = YES.But indeed, i realy do not know why this happens only on IOS 7.

ios Xcode Debugging - strange bug - Dismissing View Controller

I have literally been tearing my hair out for the past couple of days, as I have a bug in my app that seems to strike at random! I thought I would ask on here to see if anyone has had a similar experience.
The app is just crashing when a certain view controller is loaded. But this only seems to happen 1 out of every 25-30 times - so it just seems completely random to me!
The console shows the following error
Warning: Attempt to dismiss from view controller <UINavigationController: 0x1f025c30> while a presentation or dismiss is in progress!
The app then crashes.
However, there is not actually any code to dismiss this view controller - I use JASidepanels (https://github.com/gotosleep/JASidePanels) however this bug only occurs with one view. So as there is no code to dismiss it, I really am not sure how this is happening. (JASidepanels slides and hides this panel - but this is not called when the view loads)
Below is the symbolicated crash report - I really cannot find much of use in here at all:
Incident Identifier: 8E0C4F14-1B7B-4241-A1D3-37AD55F3D432
CrashReporter Key: fb5a345eac1c4c3ba4fbe6158b1d6af5833f137e
Hardware Model: iPad2,7
Process: appName [7665]
Path: /var/mobile/Applications/130C6C0F-40E0-4EE7-AD2A-F7CFCFD6C462/appName.app/appName
Identifier: appName
Version: ??? (???)
Code Type: ARM (Native)
Parent Process: launchd [1]
Date/Time: 2013-07-02 14:24:24.588 +0100
OS Version: iOS 6.1.3 (10B329)
Report Version: 104
Exception Type: EXC_CRASH (SIGABRT)
Exception Codes: 0x0000000000000000, 0x0000000000000000
Crashed Thread: 9
Last Exception Backtrace:
0 CoreFoundation 0x32f5729e __exceptionPreprocess + 158
1 libobjc.A.dylib 0x3ae1297a objc_exception_throw + 26
2 CoreFoundation 0x32f56d80 __NSFastEnumerationMutationHandler + 124
3 UIKit 0x34d6ff92 -[UIView(Hierarchy) subviews] + 326
4 UIKit 0x34d7b04a -[UIView(Geometry) resizeSubviewsWithOldSize:] + 22
5 UIKit 0x3519cc28 -[UIView(AdditionalLayoutSupport) _is_layout] + 112
6 UIKit 0x34d68a8c -[UIView(Hierarchy) layoutSubviews] + 68
7 UIKit 0x34d627fe -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 254
8 QuartzCore 0x34b0cd86 -[CALayer layoutSublayers] + 210
9 QuartzCore 0x34b0c924 CA::Layer::layout_if_needed(CA::Transaction*) + 456
10 QuartzCore 0x34b0d858 CA::Layer::layout_and_display_if_needed(CA::Transaction*) + 12
11 QuartzCore 0x34b0d23e CA::Context::commit_transaction(CA::Transaction*) + 234
12 QuartzCore 0x34b0d04c CA::Transaction::commit() + 312
13 QuartzCore 0x34b0ceac CA::Transaction::observer_callback(__CFRunLoopObserver*, unsigned long, void*) + 56
14 CoreFoundation 0x32f2c6c8 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 16
15 CoreFoundation 0x32f2a9bc __CFRunLoopDoObservers + 272
16 CoreFoundation 0x32f2ad12 __CFRunLoopRun + 738
17 CoreFoundation 0x32e9deb8 CFRunLoopRunSpecific + 352
18 CoreFoundation 0x32e9dd44 CFRunLoopRunInMode + 100
19 GraphicsServices 0x36a692e6 GSEventRunModal + 70
20 UIKit 0x34db32fc UIApplicationMain + 1116
21 appName 0x0009c1a2 main (main.m:16)
22 libdyld.dylib 0x3b249b1c start + 0
And thread 9 - that crashed:
Thread 9 Crashed:
0 libsystem_kernel.dylib 0x3b310d98 __workq_kernreturn + 8
1 libsystem_c.dylib 0x3b25ecf6 _pthread_workq_return + 14
2 libsystem_c.dylib 0x3b25ea12 _pthread_wqthread + 362
3 libsystem_c.dylib 0x3b25e8a0 start_wqthread + 4
Any help would be greatly appreciated!
Dismissing a Presented View Controller
When it comes time to dismiss a presented view controller, the
preferred approach is to let the presenting view controller dismiss
it. In other words, whenever possible, the same view controller that
presented the view controller should also take responsibility for
dismissing it. Although there are several techniques for notifying the
presenting view controller that its presented view controller should
be dismissed, the preferred technique is delegation. For more
information, see “Using Delegation to Communicate with Other
Controllers.”
Make sure that you don't dismiss you viewController inside this viewcontroller(according to the documentation). The best way dismiss viewController outside use delegate.
“Using Delegation to Communicate with Other Controllers.”
Try to use
if (![self.presentedViewController isBeingPresented]) {
}
I don't think this is connected with modal/presented view controllers at all.
From the stack trace only one thing is clear - it's a typical exception caused by changing objects in collection while enumerating them in the same time. In this case the collection is probably the of subviews (your main thread is enumerating them).
One of the usual causes is updating the view hierarchy from a secondary thread (not the main thread).

Resources