I am getting a (what seems to me as a strange) crash with Core Data.
From what I can gather it is happening when Core Data does a save and subsequent managedObjectContextDidSave methods are fired.
I am at a loss and really hoping someone can help me out or guide me in the right direction.
The crash report is as follows:
Exception Type: EXC_BAD_ACCESS (SIGBUS)
Exception Codes: KERN_PROTECTION_FAILURE at 0x0000000b
Crashed Thread: 0
Thread 0 Crashed:
0 libobjc.A.dylib 0x000026f4 objc_msgSend + 16
1 Foundation 0x000437a4 NSClassFromObject + 8
2 Foundation 0x0000ba54 _NSIMPForObjectAndSelector + 4
3 Foundation 0x00095eae -[NSSortDescriptor compareObject:toObject:] + 110
4 CoreData 0x000b0a6e +[NSFetchedResultsController(PrivateMethods) _insertIndexForObject:inArray:lowIdx:highIdx:sortDescriptors:] + 174
5 CoreData 0x000b1496 -[NSFetchedResultsController(PrivateMethods) _postprocessInsertedObjects:] + 342
6 CoreData 0x000b32d6 -[NSFetchedResultsController(PrivateMethods) _postprocessUpdatedObjects:] + 430
7 CoreData 0x000b2a5e -[NSFetchedResultsController(PrivateMethods) _managedObjectContextDidChange:] + 498
8 Foundation 0x0004bbf6 _nsnote_callback + 162
9 CoreFoundation 0x00050af2 _CFXNotificationPostNotification + 298
10 Foundation 0x000497f4 -[NSNotificationCenter postNotificationName:object:userInfo:] + 64
11 CoreData 0x0002e42e -[NSManagedObjectContext(_NSInternalNotificationHandling) _postObjectsDidChangeNotificationWithUserInfo:] + 66
12 CoreData 0x0007fd26 -[NSManagedObjectContext(_NSInternalChangeProcessing) _createAndPostChangeNotification:withDeletions:withUpdates:withRefreshes:] + 134
13 CoreData 0x0001670a -[NSManagedObjectContext(_NSInternalChangeProcessing) _postRefreshedObjectsNotificationAndClearList] + 70
14 CoreData 0x000164ac -[NSManagedObjectContext(_NSInternalChangeProcessing) _processRecentChanges:] + 1656
15 CoreData 0x0004b5fa -[NSManagedObjectContext processPendingChanges] + 10
16 CoreData 0x0003e2a4 _performRunLoopAction + 120
17 CoreFoundation 0x0000fb50 __CFRunLoopDoObservers + 420
18 CoreFoundation 0x00056a32 CFRunLoopRunSpecific + 1734
19 CoreFoundation 0x00056356 CFRunLoopRunInMode + 42
20 GraphicsServices 0x00003cb8 GSEventRunModal + 108
21 GraphicsServices 0x00003d64 GSEventRun + 56
22 UIKit 0x00002768 -[UIApplication _run] + 384
23 UIKit 0x0000146c UIApplicationMain + 688
24 MyApp 0x000022d2 main (main.m:14)
25 MyApp 0x00002248 start + 44
It looks like one of the items in one of your database arrays is getting released one too many times (and therefore gets deallocated). It’s crashing trying to sort your array, making a comparison with a deallocated object.
Try running your program with NSZombieEnabled — it prevents the deallocation so you can see which object is getting messages sent to it with a retain count of 0.