This question already has an answer here:
insertObject: atIndex: - index 3 beyond bounds for empty array
(1 answer)
Closed 8 years ago.
I'm getting this crash. Here is my crash reason. I didn't understand what I am doing.
reason: '*** -[__NSArrayM objectAtIndex:]: index 2 beyond bounds for empty array'
*** First throw call stack:
(
0 CoreFoundation 0x036131e4 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x02c1c8e5 objc_exception_throw + 44
2 CoreFoundation 0x035b43f6 -[__NSArrayM objectAtIndex:] + 246
3 Stampd 0x0007e928 -[VenueProfile tableView:cellForRowAtIndexPath:] + 472
4 UIKit 0x017c811f -[UITableView _createPreparedCellForGlobalRow:withIndexPath:] + 412
5 UIKit 0x017c81f3 -[UITableView _createPreparedCellForGlobalRow:] + 69
6 UIKit 0x017a9ece -[UITableView _updateVisibleCellsNow:] + 2428
7 UIKit 0x017be6a5 -[UITableView layoutSubviews] + 213
8 UIKit 0x0173e964 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 355
9 libobjc.A.dylib 0x02c2e82b -[NSObject performSelector:withObject:] + 70
10 QuartzCore 0x0055945a -[CALayer layoutSublayers] + 148
11 QuartzCore 0x0054d244 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 380
12 QuartzCore 0x0054d0b0 _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 26
13 QuartzCore 0x004b37fa _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 294
14 QuartzCore 0x004b4b85 _ZN2CA11Transaction6commitEv + 393
15 QuartzCore 0x00581cc6 _ZN2CA7Display11DisplayLink14dispatch_itemsEyyy + 474
16 QuartzCore 0x00582147 _ZN2CA7Display16TimerDisplayLink8callbackEP16__CFRunLoopTimerPv + 123
17 CoreFoundation 0x035d1ac6 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 22
18 CoreFoundation 0x035d14ad __CFRunLoopDoTimer + 1181
19 CoreFoundation 0x035b9538 __CFRunLoopRun + 1816
20 CoreFoundation 0x035b89d3 CFRunLoopRunSpecific + 467
21 CoreFoundation 0x035b87eb CFRunLoopRunInMode + 123
22 GraphicsServices 0x03bdb5ee GSEventRunModal + 192
23 GraphicsServices 0x03bdb42b GSEventRun + 104
24 UIKit 0x016cff9b UIApplicationMain + 1225
25 Stampd 0x000044e2 main + 130
26 libdyld.dylib 0x0431d701 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
The error
[__NSArrayM objectAtIndex:]: index 2 beyond bounds for empty array
clearly states that, trying to access the empty array. Check the array as alloc & init and has objects in it
Put your array in NSLog at the method numberOfRowsInSection. This will give you objects in the array and if array is empty please check if you initialize your array properly. If not, alloc and init your array before adding objects into it.
Related
Right after updating Xcode to 8.3, I started receiving this error at launch: Terminating app due to uncaught exception 'CALayerInvalidGeometry', reason: 'CALayer position contains NaN: [nan nan]'
The main view for my app has a couple of container views, one of which holds a mapView. It appears the error has to do with the map, but I can't quite make out from the message what that might be. Any thoughts would be greatly appreciated!
*** Terminating app due to uncaught exception 'CALayerInvalidGeometry', reason: 'CALayer position contains NaN: [nan nan]'
*** First throw call stack:
(
0 CoreFoundation 0x00000001029b1b0b __exceptionPreprocess + 171
1 libobjc.A.dylib 0x0000000102416141 objc_exception_throw + 48
2 CoreFoundation 0x0000000102a1a625 +[NSException raise:format:] + 197
3 QuartzCore 0x00000001039d90be _ZN2CA5Layer12set_positionERKNS_4Vec2IdEEb + 152
4 QuartzCore 0x00000001039d9231 -[CALayer setPosition:] + 43
5 MapKit 0x000000010354a97b -[MKMapView _updateScrollContainerView:] + 1214
6 MapKit 0x000000010354bbeb -[MKMapView _sizeDidChangeWithCenterCoordinate:] + 55
7 MapKit 0x000000010354606e -[MKMapView setBounds:] + 271
8 UIKit 0x0000000103c14b23 -[UIView(Geometry) _applyISEngineLayoutValuesToBoundsOnly:] + 598
9 UIKit 0x0000000103c14e0e -[UIView(Geometry) _resizeWithOldSuperviewSize:] + 125
10 CoreFoundation 0x0000000102942652 __53-[__NSArrayM enumerateObjectsWithOptions:usingBlock:]_block_invoke + 114
11 CoreFoundation 0x000000010294256f -[__NSArrayM enumerateObjectsWithOptions:usingBlock:] + 335
12 UIKit 0x0000000103c1387c -[UIView(Geometry) resizeSubviewsWithOldSize:] + 183
13 UIKit 0x000000010452f1f9 -[UIView(AdditionalLayoutSupport) _is_layout] + 168
14 UIKit 0x0000000103c1fd56 -[UIView(Hierarchy) _updateConstraintsAsNecessaryAndApplyLayoutFromEngine] + 994
15 UIKit 0x0000000103c3120b -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 1268
16 QuartzCore 0x00000001039e2904 -[CALayer layoutSublayers] + 146
17 QuartzCore 0x00000001039d6526 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 370
18 QuartzCore 0x00000001039d63a0 _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 24
19 QuartzCore 0x0000000103965e92 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 294
20 QuartzCore 0x0000000103992130 _ZN2CA11Transaction6commitEv + 468
21 QuartzCore 0x0000000103992b37 _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 115
22 CoreFoundation 0x0000000102957717 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23
23 CoreFoundation 0x0000000102957687 __CFRunLoopDoObservers + 391
24 CoreFoundation 0x000000010293c038 CFRunLoopRunSpecific + 440
25 UIKit 0x0000000103b6802f -[UIApplication _run] + 468
26 UIKit 0x0000000103b6e0d4 UIApplicationMain + 159
27 Pulley 0x0000000101bd95b7 main + 55
28 libdyld.dylib 0x0000000109eaa65d start + 1
29 ??? 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
It seems that you are doing setPosition: using CALayer object and that CALayer object is nil. Thats why your app is crashed.
please check that CALayer is nil or not by if statement.
I figured it out. The problem stemmed from a 3rd party extension I was using for MapKit. After removing my mapView from storyboard and creating a new one programmatically, a new error pointed me to methods in the extension.
I'm developing an app that uses SQLITE and works perfectly on Iphone 6plus simulator but crash on Iphone6 simulator and also on Iphone5. I'm not sure what's the problem. Can anyone help me with that?
This is the debug error that I'm getting from Xcode
*** Terminating app due to uncaught exception 'NSRangeException', reason:
*** -[__NSArrayM objectAtIndex:]: index 9223372036854775807 beyond bounds [0 .. 10]'
*** First throw call stack:
(
0 CoreFoundation 0x000000010492ae65 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x00000001043a3deb objc_exception_throw + 48
2 CoreFoundation 0x000000010480e404 -[__NSArrayM objectAtIndex:] + 212
3 ILFCalc 0x0000000103d85cf8 -[EditInfoViewController loadInfoToEdit] + 424
4 ILFCalc 0x0000000103d83f76 -[EditInfoViewController viewDidLoad] + 1174
5 UIKit 0x0000000104e6df98 -[UIViewController loadViewIfRequired] + 1198
6 UIKit 0x0000000104e73f4f -[UIViewController __viewWillAppear:] + 120
7 UIKit 0x0000000104ea3e44 -[UINavigationController _startCustomTransition:] + 1203
8 UIKit 0x0000000104eb423f -[UINavigationController _startDeferredTransitionIfNeeded:] + 712
9 UIKit 0x0000000104eb53af -[UINavigationController __viewWillLayoutSubviews] + 57
10 UIKit 0x000000010505bff7 -[UILayoutContainerView layoutSubviews] + 248
11 UIKit 0x0000000104d8e4a3 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 703
12 QuartzCore 0x000000010874559a -[CALayer layoutSublayers] + 146
13 QuartzCore 0x0000000108739e70 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 366
14 QuartzCore 0x0000000108739cee _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 24
15 QuartzCore 0x000000010872e475 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 277
16 QuartzCore 0x000000010875bc0a _ZN2CA11Transaction6commitEv + 486
17 QuartzCore 0x000000010875c37c _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 92
18 CoreFoundation 0x0000000104856367 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23
19 CoreFoundation 0x00000001048562d7 __CFRunLoopDoObservers + 391
20 CoreFoundation 0x000000010484bf2b __CFRunLoopRun + 1147
21 CoreFoundation 0x000000010484b828 CFRunLoopRunSpecific + 488
22 GraphicsServices 0x0000000107fd2ad2 GSEventRunModal + 161
23 UIKit 0x0000000104cd7610 UIApplicationMain + 171
24 ILFCalc 0x0000000103d898af main + 111
25 libdyld.dylib 0x000000010631a92d start + 1
26 ??? 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
This is the error:
* Terminating app due to uncaught exception 'NSRangeException', reason: '* -[__NSArrayI objectAtIndex:]: index 18446744073709551615 beyond bounds [0 .. 1]'
*** First throw call stack:
(
0 CoreFoundation 0x0000000104b09f45 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x0000000104edbdeb objc_exception_throw + 48
2 CoreFoundation 0x00000001049f8b14 -[__NSArrayI objectAtIndex:] + 164
3 MyApp 0x000000010234ae4b -[AppManager homePage] + 203
4 MyApp 0x000000010234a437 -[AppManager init] + 503
5 MyApp 0x000000010234a222 __28+[AppManager sharedInstance]_block_invoke + 50
6 libdispatch.dylib 0x00000001061da49b _dispatch_client_callout + 8
7 libdispatch.dylib 0x00000001061c5e28 dispatch_once_f + 543
8 MyApp 0x000000010234a1cb +[AppManager sharedInstance] + 107
9 MyApp 0x000000010238494b -[SplashViewController viewDidLoad] + 379
10 UIKit 0x0000000103652cc4 -[UIViewController loadViewIfRequired] + 1198
11 UIKit 0x00000001036970ee -[UINavigationController _layoutViewController:] + 54
12 UIKit 0x00000001036979c2 -[UINavigationController _updateScrollViewFromViewController:toViewController:] + 462
13 UIKit 0x0000000103697b34 -[UINavigationController _startTransition:fromViewController:toViewController:] + 126
14 UIKit 0x0000000103698d8d -[UINavigationController _startDeferredTransitionIfNeeded:] + 890
15 UIKit 0x0000000103699cea -[UINavigationController __viewWillLayoutSubviews] + 57
16 UIKit 0x000000010383fc85 -[UILayoutContainerView layoutSubviews] + 248
17 UIKit 0x0000000103574e40 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 710
18 QuartzCore 0x000000010324059a -[CALayer layoutSublayers] + 146
19 QuartzCore 0x0000000103234e70 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 366
20 QuartzCore 0x0000000103234cee _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 24
21 QuartzCore 0x0000000103229475 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 277
22 QuartzCore 0x0000000103256c0a _ZN2CA11Transaction6commitEv + 486
23 QuartzCore 0x000000010325737c _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 92
24 CoreFoundation 0x0000000104a35947 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23
25 CoreFoundation 0x0000000104a358b7 __CFRunLoopDoObservers + 391
26 CoreFoundation 0x0000000104a2ae2c CFRunLoopRunSpecific + 524
27 UIKit 0x00000001034bb4f5 -[UIApplication _run] + 402
28 UIKit 0x00000001034c030d UIApplicationMain + 171
29 MyApp 0x000000010239b63f main + 111
30 libdyld.dylib 0x000000010620e92d start + 1
31 ??? 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
I'm not accessing any object inside NSArray which leads to following error, however certainly my app giving me this error.
The error is in your homePage method, which you can see here:
2 CoreFoundation ... -[__NSArrayI objectAtIndex:] + 164
3 MyApp ... -[AppManager homePage] + 203 <----THIS CALLS objectAtIndex: ABOVE
According to the error message, it is trying to access the index 18446744073709551615. This is the value of NSNotFound, which means you are probably handling NSNotFound incorrectly!
Issue with -[AppManager homePage] method kindly check if there is any array accessed there
The application I work on is displaying a CollectionView in form of a calendar.
To simplify that we used the MSCollectionViewCalendarLayout from github.
Now it comes with multiple additional decoration views like a red line, which represents the current time in the calendar.
In our implementation there is also the possibility of filtering for different types, so the calendar not always displays the same kind/amount of cells. Unfortunately sometimes the application crashes just out of nowhere, when it should display the red timeline:
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'request for layout attributes for decoration view of kind MSCollectionElementKindCurrentTimeHorizontalGridline in section 0 when there are only 0 sections in the collection view'
*** First throw call stack:
(
0 CoreFoundation 0x034761e4 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x02fcb8e5 objc_exception_throw + 44
2 CoreFoundation 0x03476048 +[NSException raise:format:arguments:] + 136
3 Foundation 0x00e2f4de -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 116
4 UIKit 0x018eb290 -[UICollectionViewData layoutAttributesForDecorationViewOfKind:atIndexPath:] + 228
5 UIKit 0x018b5764 -[UICollectionView _dequeueReusableViewOfKind:withIdentifier:forIndexPath:viewCategory:] + 242
6 UIKit 0x018a8036 -[UICollectionView _createPreparedSupplementaryViewForElementOfKind:atIndexPath:withLayoutAttributes:applyAttributes:] + 381
7 UIKit 0x018a9775 -[UICollectionView _updateVisibleCellsNow:] + 4730
8 UIKit 0x018ad65f -[UICollectionView layoutSubviews] + 265
9 UIKit 0x012d0964 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 355
10 libobjc.A.dylib 0x02fdd82b -[NSObject performSelector:withObject:] + 70
11 QuartzCore 0x026a445a -[CALayer layoutSublayers] + 148
12 QuartzCore 0x02698244 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 380
13 QuartzCore 0x026980b0 _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 26
14 QuartzCore 0x025fe7fa _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 294
15 QuartzCore 0x025ffb85 _ZN2CA11Transaction6commitEv + 393
16 QuartzCore 0x02600258 _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 92
17 CoreFoundation 0x0343e36e __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 30
18 CoreFoundation 0x0343e2bf __CFRunLoopDoObservers + 399
19 CoreFoundation 0x0341c254 __CFRunLoopRun + 1076
20 CoreFoundation 0x0341b9d3 CFRunLoopRunSpecific + 467
21 CoreFoundation 0x0341b7eb CFRunLoopRunInMode + 123
22 GraphicsServices 0x049615ee GSEventRunModal + 192
23 GraphicsServices 0x0496142b GSEventRun + 104
24 UIKit 0x01261f9b UIApplicationMain + 1225
25 CariAudit 0x001036ad main + 141
26 libdyld.dylib 0x039d9701 start + 1
27 ??? 0x00000003 0x0 + 3
)
libc++abi.dylib: terminating with uncaught exception of type NSException
Now I know that with this custom layout, many people get this error message when they change the underlying data of the collectionView and the solution to this is to call "invalidateLayoutCache" on the layout. The only problem is that I already have that in my code and it gets called before calling reloadData on the collectionView.
Does anyone maybe have an idea/approach for solving this kind of problem?
Thanks
After hours of searching I finally managed to find the error.
The problem was that the MSCollectionViewCalendarLayout missed to empty the Attributes-Dictionaries
currentTimeIndicatorAttributes and currentTimeHorizontalGridlineAttributes.
To fix the error all I had to do was to expand the invalidateLayoutCache method with the following:
[self.currentTimeIndicatorAttributes removeAllObjects];
[self.currentTimeHorizontalGridlineAttributes removeAllObjects];
What i have Done?
In one of my UIViewController child i have implemented UITableView and have implemented the necessary UITableViewDelegate functions.
What i am Facing?
The issue i am facing is that i get EXC_BAD_ACCESS in Application whenever i relaunch the Controller and tap on Any cell.
What i have Tried?
I have tried to place breakpoints in the function didDeselectRowAtIndexPath: but it never reaches the Breakpoint. I tried Global Exception Breakpoint but it also didn't worked. I checked using the Instruments and found that a zombie is detechted when didDeselectRowAtIndexPath is called but control doesn't reaches the Function.
Instruments Zombie Details Image - Photo Bucket Link
After Implementing the Given Suggestions in the Comments this is the log that i have received
*** -[__NSArrayM insertObject:atIndex:]: object cannot be nil'
*** First throw call stack:
(
0 CoreFoundation 0x023e11e4 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x01fc98e5 objc_exception_throw + 44
2 CoreFoundation 0x02393abc -[__NSArrayM insertObject:atIndex:] + 844
3 CoreFoundation 0x02393760 -[__NSArrayM addObject:] + 64
4 UIKit 0x00bf5782 -[UITableViewIndex _displayTitles] + 1071
5 UIKit 0x00bf58a8 -[UITableViewIndex _cacheAndMeasureTitles] + 171
6 UIKit 0x00bf6213 -[UITableViewIndex sizeThatFits:] + 131
7 UIKit 0x00a18bbc -[UITableView _updateIndexFrameSuppressingChangeNotification:] + 513
8 UIKit 0x00a189b6 -[UITableView _updateIndexFrame] + 41
9 UIKit 0x00a19a5f -[UITableView _updateIndex] + 649
10 UIKit 0x00a336f7 -[UITableView layoutSubviews] + 295
11 UIKit 0x009b3964 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 355
12 libobjc.A.dylib 0x01fdb82b -[NSObject performSelector:withObject:] + 70
13 QuartzCore 0x002ba45a -[CALayer layoutSublayers] + 148
14 QuartzCore 0x002ae244 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 380
15 QuartzCore 0x002ae0b0 _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 26
16 QuartzCore 0x002147fa _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 294
17 QuartzCore 0x00215b85 _ZN2CA11Transaction6commitEv + 393
18 QuartzCore 0x00216258 _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 92
19 CoreFoundation 0x023a936e __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 30
20 CoreFoundation 0x023a92bf __CFRunLoopDoObservers + 399
21 CoreFoundation 0x02387254 __CFRunLoopRun + 1076
22 CoreFoundation 0x023869d3 CFRunLoopRunSpecific + 467
23 CoreFoundation 0x023867eb CFRunLoopRunInMode + 123
24 GraphicsServices 0x0381a5ee GSEventRunModal + 192
25 GraphicsServices 0x0381a42b GSEventRun + 104
26 UIKit 0x00944f9b UIApplicationMain + 1225
27 MyApplication 0x00001f9c main + 76
28 libdyld.dylib 0x034b3701 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
It is pretty clear from all the logs and Zombie images that you are accessing the deallocated CountryListViewController. Keep track on the CountryListViewController and check it is available while you processing your table-view operations.
The better option is, Go to Xcode Menu Product->Scheme->Mange Schemes->Edit (left bottom)-> Debug-> Diagnostics -> Check all the options -> then Run the project.
This will be the Lighthouse to discover your crash.