Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Crashes with [__NSArrayM objectAtIndex:]: index 0 beyond bounds for empty array error

I am getting crash reports via users of my iOS app, but crash I can't reproduce myself, nor can I trace the error back to a line in my own code (except that it originates from line 14 in main.m but this is the default application creation of iOS apps. Below the a crash report I received.

In understand that at some point a object is at index 0 is being retrieved from an empty Array. But since it doesn't seem to point to my own code, can it be a bug in iOS? (It happens on different platforms and with different iOS versions).

I hope someone has an idea what is happening or can point me in the right direction. Thanks.

CRASH REPORT:

Incident Identifier: [TODO]
CrashReporter Key:   [TODO]
Process:         Mary Black [797]
Path:            /var/mobile/Applications/28A68F8B-294E-4B86-9E75-ED5484E5EF4D/Mary Black.app/Mary Black
Identifier:      net.broset.Mary-Black
Version:         225
Code Type:       ARM (Native)
Parent Process:  launchd [1]

Date/Time:       2011-10-14 03:47:32 +0000
OS Version:      iPhone OS 5.0 (9A334)
Report Version:  104

Exception Type:  SIGTRAP
Exception Codes: #0 at 0x35b07848
Crashed Thread:  0

Application Specific Information:
*** Terminating app due to uncaught exception \\\'NSRangeException\\\', reason: \\\'*** -[__NSArrayM objectAtIndex:]: index 0 beyond bounds for empty array\\\'

Thread 0 Crashed:
0   libsystem_kernel.dylib              0x00010848 __kill + 8
1   CoreFoundation                      0x000b9987 __handleUncaughtException + 75
2   libobjc.A.dylib                     0x000092d1 _objc_terminate + 129
3   libc++abi.dylib                     0x000043c5 _ZL19safe_handler_callerPFvvE + 77
4   libc++abi.dylib                     0x00004451 operator delete(void*) + 1
5   libc++abi.dylib                     0x00005825 __cxa_current_exception_type + 1
6   libobjc.A.dylib                     0x00009235 objc_exception_rethrow + 13
7   CoreFoundation                      0x0000f545 CFRunLoopRunSpecific + 405
8   CoreFoundation                      0x0000f3a5 CFRunLoopRunInMode + 105
9   GraphicsServices                    0x00003fed GSEventRunModal + 157
10  UIKit                               0x00031743 UIApplicationMain + 1091
11  Mary Black                          0x00002fa7 main (main.m:14)
like image 339
msetten Avatar asked Oct 22 '11 12:10

msetten


2 Answers

One way to debug this issue is to add a Symbolic Breakpoint on objectAtIndex: This may result in many hits to objectAtIndex: before the debugger hits the one you're after but it's guaranteed to find it.

Steps in Xcode 4:

  • View > Navigators > Breakpoint Navigator
  • click '+' and choose Add Symbolic Breakpoint in the pop-up
  • type in "objectAtIndex:" in the Symbol text field and click Done

at runtime, if you can't tell which objectAtIndex: you're hitting, move the slider at the bottom of the Debug Navigator all the way to the right.

like image 162
maz Avatar answered Sep 23 '22 10:09

maz


This will stop the debugger at the offending line:

Xcode/Edit Scheme/Diagnostics/Log Exceptions.

like image 28
Michael Superczynski Avatar answered Sep 24 '22 10:09

Michael Superczynski