My ios app used a lot of Core Data and Core Animation. Due to multi-threading, it sometimes crashed in an irreproducible fashion. Can any programming ninja help on looking into this crash issues? I don't have an idea where I had an empty mutablearray
being called objectAtIndex
.
Also I don't know how to track where the CGContext
errors happened. Since it's not an NSException
, I don't how to set a breakpoint there. Can anyone teach me how to set breakpoint whenever CGContext
errors come up?
My console log:
May 30 09:12:39 Dons-iPod-touch larklife[6914] <Warning>: EventsViewController.m 680: indexPath in finish block<NSIndexPath 0x1f18fe60> 2 indexes [1, 0]
May 30 09:12:39 Dons-iPod-touch larklife[6914] <Error>: CGContextSetFillColorWithColor: invalid context 0x0
May 30 09:12:39 Dons-iPod-touch larklife[6914] <Error>: CGContextSaveGState: invalid context 0x0
May 30 09:12:39 Dons-iPod-touch larklife[6914] <Error>: CGContextSetFlatness: invalid context 0x0
May 30 09:12:39 Dons-iPod-touch larklife[6914] <Error>: CGContextAddPath: invalid context 0x0
May 30 09:12:39 Dons-iPod-touch larklife[6914] <Error>: CGContextDrawPath: invalid context 0x0
May 30 09:12:39 Dons-iPod-touch larklife[6914] <Error>: CGContextRestoreGState: invalid context 0x0
May 30 09:12:40 Dons-iPod-touch larklife[6914] <Error>: *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayM objectAtIndex:]: index 0 beyond bounds for empty array'
*** First throw call stack:
(0x330e92a3 0x3ad6797f 0x33034b75 0x32f5bc0d 0xeb555 0xe5c9b 0x106549 0xe1521 0xebcad 0xde557 0xe4589 0xe5275 0x24b06d 0x339f7277 0x330be5df 0x330be291 0x330bcf01 0x3302febd 0x3302fd49 0x36be22eb 0x34f45301 0x206fd 0x3b19eb20)
Crash report:
Incident Identifier: C18D4D70-7157-4456-900B-077BDE488A70
CrashReporter Key: 7531fede04c2aea4fcfb40a804a8e2fdb0a4cb79
Hardware Model: iPod4,1
Process: larklife [6914]
Path: /var/mobile/Applications/30FAAA4E-1FC4-452F-82E2- 1E706A34A0B8/larklife.app/larklife
Identifier: larklife
Version: ??? (???)
Code Type: ARM (Native)
Parent Process: launchd [1]
Date/Time: 2013-05-30 09:12:40.483 -0700
OS Version: iOS 6.1.3 (10B329)
Report Version: 104
Exception Type: EXC_CRASH (SIGABRT)
Exception Codes: 0x0000000000000000, 0x0000000000000000
Crashed Thread: 0
Last Exception Backtrace:
0 CoreFoundation 0x330e929e __exceptionPreprocess + 158
1 libobjc.A.dylib 0x3ad6797a objc_exception_throw + 26
2 CoreFoundation 0x33034b70 -[__NSArrayM objectAtIndex:] + 160
3 CoreData 0x32f5bc08 -[NSFetchedResultsController objectAtIndexPath:] + 236
4 larklife 0x000eb550 0x19000 + 861520
5 larklife 0x000e5c96 0x19000 + 838806
6 larklife 0x00106544 0x19000 + 972100
7 larklife 0x000e151c 0x19000 + 820508
8 larklife 0x000ebca8 0x19000 + 863400
9 larklife 0x000de552 0x19000 + 808274
10 larklife 0x000e4584 0x19000 + 832900
11 larklife 0x000e5270 0x19000 + 836208
12 larklife 0x0024b068 0x19000 + 2302056
13 Foundation 0x339f7272 __NSFireDelayedPerform + 446
14 CoreFoundation 0x330be5da __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 10
15 CoreFoundation 0x330be28c __CFRunLoopDoTimer + 268
16 CoreFoundation 0x330bcefc __CFRunLoopRun + 1228
17 CoreFoundation 0x3302feb8 CFRunLoopRunSpecific + 352
18 CoreFoundation 0x3302fd44 CFRunLoopRunInMode + 100
19 GraphicsServices 0x36be22e6 GSEventRunModal + 70
20 UIKit 0x34f452fc UIApplicationMain + 1116
21 larklife 0x000206f8 0x19000 + 30456
22 libdyld.dylib 0x3b19eb1c start + 0
Thread 0 name: Dispatch queue: com.apple.main-thread
Thread 0 Crashed:
0 libsystem_kernel.dylib 0x3b265350 __pthread_kill + 8
1 libsystem_c.dylib 0x3b1dc11e pthread_kill + 54
2 libsystem_c.dylib 0x3b21896e abort + 90
3 libc++abi.dylib 0x3a7b6d4a abort_message + 70
4 libc++abi.dylib 0x3a7b3ff4 _ZL17default_terminatev + 20
5 libobjc.A.dylib 0x3ad67a74 _ZL15_objc_terminatev + 144
6 libc++abi.dylib 0x3a7b4078 _ZL19safe_handler_callerPFvvE + 76
7 libc++abi.dylib 0x3a7b4110 std::terminate() + 16
8 libc++abi.dylib 0x3a7b5594 __cxa_rethrow + 84
9 libobjc.A.dylib 0x3ad679cc objc_exception_rethrow + 8
10 CoreFoundation 0x3302ff1c CFRunLoopRunSpecific + 452
11 CoreFoundation 0x3302fd44 CFRunLoopRunInMode + 100
12 GraphicsServices 0x36be22e6 GSEventRunModal + 70
13 UIKit 0x34f452fc UIApplicationMain + 1116
14 larklife 0x000206f8 0x19000 + 30456
15 libdyld.dylib 0x3b19eb1c start + 0
Thread 1 name: Dispatch queue: com.apple.libdispatch-manager
Thread 1:
0 libsystem_kernel.dylib 0x3b255648 kevent64 + 24
1 libdispatch.dylib 0x3b18e4ec _dispatch_mgr_invoke + 792
2 libdispatch.dylib 0x3b180df4 _dispatch_mgr_thread$VARIANT$up + 32
Thread 2 name: WebThread
Thread 2:
0 libsystem_kernel.dylib 0x3b254eb4 mach_msg_trap + 20
1 libsystem_kernel.dylib 0x3b255048 mach_msg + 36
2 CoreFoundation 0x330be040 __CFRunLoopServiceMachPort + 124
3 CoreFoundation 0x330bcd9e __CFRunLoopRun + 878
4 CoreFoundation 0x3302feb8 CFRunLoopRunSpecific + 352
5 CoreFoundation 0x3302fd44 CFRunLoopRunInMode + 100
6 WebCore 0x3901d500 _ZL12RunWebThreadPv + 440
7 libsystem_c.dylib 0x3b1be30e _pthread_start + 306
8 libsystem_c.dylib 0x3b1be1d4 thread_start + 4
Thread 3:
0 libsystem_kernel.dylib 0x3b265d98 __workq_kernreturn + 8
1 libsystem_c.dylib 0x3b1b3cf6 _pthread_workq_return + 14
2 libsystem_c.dylib 0x3b1b3a12 _pthread_wqthread + 362
3 libsystem_c.dylib 0x3b1b38a0 start_wqthread + 4
Thread 4:
0 libsystem_kernel.dylib 0x3b265d98 __workq_kernreturn + 8
1 libsystem_c.dylib 0x3b1b3cf6 _pthread_workq_return + 14
2 libsystem_c.dylib 0x3b1b3a12 _pthread_wqthread + 362
3 libsystem_c.dylib 0x3b1b38a0 start_wqthread + 4
Thread 5 name: com.apple.NSURLConnectionLoader
Thread 5:
0 libsystem_kernel.dylib 0x3b254eb4 mach_msg_trap + 20
1 libsystem_kernel.dylib 0x3b255048 mach_msg + 36
2 CoreFoundation 0x330be040 __CFRunLoopServiceMachPort + 124
3 CoreFoundation 0x330bcd9e __CFRunLoopRun + 878
4 CoreFoundation 0x3302feb8 CFRunLoopRunSpecific + 352
5 CoreFoundation 0x3302fd44 CFRunLoopRunInMode + 100
6 Foundation 0x3397c3d0 +[NSURLConnection(Loader) _resourceLoadLoop:] + 304
7 Foundation 0x339ffe80 __NSThread__main__ + 968
8 libsystem_c.dylib 0x3b1be30e _pthread_start + 306
9 libsystem_c.dylib 0x3b1be1d4 thread_start + 4
Thread 6 name: com.apple.CFSocket.private
Thread 6:
0 libsystem_kernel.dylib 0x3b265594 __select + 20
1 CoreFoundation 0x330c21f2 __CFSocketManager + 674
2 libsystem_c.dylib 0x3b1be30e _pthread_start + 306
3 libsystem_c.dylib 0x3b1be1d4 thread_start + 4
Thread 7 name: Dispatch queue: NSManagedObjectContext Queue
Thread 7:
0 CoreData 0x32ebe19c _kvcPropertysPrimitiveSetters + 0
1 CoreData 0x32edc700 _sharedIMPL_setvfk_core + 44
2 larklife 0x000ba374 0x19000 + 660340
3 CoreData 0x32ed0bf0 _PF_Handler_Public_SetProperty + 88
4 CoreData 0x32ed312a -[NSManagedObject setValue:forKey:] + 86
5 larklife 0x002314f2 0x19000 + 2196722
6 larklife 0x00060ed8 0x19000 + 294616
7 CoreFoundation 0x330dd99e __NSArrayEnumerate + 394
8 CoreFoundation 0x3303fb66 -[NSArray enumerateObjectsWithOptions:usingBlock:] + 58
9 larklife 0x00060d44 0x19000 + 294212
10 larklife 0x0005d204 0x19000 + 279044
11 CoreData 0x32ee6072 developerSubmittedBlockToNSManagedObjectContextPerform_privateasync + 66
12 libdispatch.dylib 0x3b17e996 _dispatch_queue_drain$VARIANT$up + 142
13 libdispatch.dylib 0x3b17e890 _dispatch_queue_invoke$VARIANT$up + 32
14 libdispatch.dylib 0x3b18d212 _dispatch_root_queue_drain + 190
15 libdispatch.dylib 0x3b18d3b4 _dispatch_worker_thread2 + 80
16 libsystem_c.dylib 0x3b1b3a0e _pthread_wqthread + 358
17 libsystem_c.dylib 0x3b1b38a0 start_wqthread + 4
Thread 0 crashed with ARM Thread State (32-bit):
r0: 0x00000000 r1: 0x00000000 r2: 0x00000000 r3: 0x3cd16534
r4: 0x00000006 r5: 0x3cd16b88 r6: 0x1f483d54 r7: 0x2fde7a04
r8: 0x1f483d30 r9: 0x00000400 r10: 0x00000000 r11: 0x00000000
ip: 0x00000148 sp: 0x2fde79f8 lr: 0x3b1dc123 pc: 0x3b265350
cpsr: 0x00080010
You error message said:
[__NSArrayM objectAtIndex:]: index 0 beyond bounds
. The reason probably is that using an NSMUtableArray
(__NSArrayM
) is not thread safe, see here.
Without any code provided, I suggest that you read the Threading Programming Guide cited very carefully, and correct your code accordingly.
In events viewcontroller.m
the array you used was empty at index 0 and 1. Check the 160 and 236 of your code for the error that accrued. It was definitely related to fetching data. It seems that it could not fetch data from you store. It is what i gather without seeing the actual code.
You trying to get the first element of an empty array, which produce the crash and the exception is self explanatory.
you can debug the array when the app crashes using the po
command (print object):
po the_array_object
Also, make sure you set breakpoints ON
in the breakpoint navigator in order to get better debugging stuck from the compiler.
User contributions licensed under CC BY-SA 3.0