6

I needed some help figuring out what might be going on in this crash report. This is a un-reproducible problem for me, but some users are running into this crash repeatedly at launch.

When the app launches, I load a nib which contains an NSObjectController to a ContactsListDisplaySource object, and an NSArrayController that is peopleArrayController (which is an outlet inside the ContactsListDisplaySource object). The peopleArrayController is what fetches a list of contacts from the database in ContactsListDisplaySource refetchArrayController]:

- (void) refetchArrayController {

    NSError *error = nil;
    [_peopleArrayController fetchWithRequest:nil merge:NO error:&error];
    if (error) {
        NSLog(@"error in peopleArrayController fetch = %@", error);
    }
}

EDIT: note that this is called from awakeFromNib, and that using fetch: instead of fetchWithRequest:merge:error returns 0 rows

This works 99% of the time, but I want to figure out what's going on in this crash report. Are there any clues in the crash report that can decipher the problem?

Date/Time:       2015-04-22 12:17:17 +0000
OS Version:      Mac OS X 10.10.3 (14D136)
Report Version:  104

Exception Type:  SIGSEGV
Exception Codes: SEGV_NOOP at 0x0
Crashed Thread:  0

Thread 0 Crashed:
0   libsqlite3.dylib                     0x00007fff8e3770ad sqlite3VdbeHalt + 7741
1   libsqlite3.dylib                     0x00007fff8e3bd9c7 sqlite3VdbeExec + 93206
2   libsqlite3.dylib                     0x00007fff8e3a53df sqlite3_step + 734
3   CoreData                             0x00007fff91126710 _execute + 112
4   CoreData                             0x00007fff911389b8 -[NSSQLiteConnection fetchResultSet:usingFetchPlan:] + 1880
5   CoreData                             0x00007fff91140719 newFetchedRowsForFetchPlan_MT + 2217
6   CoreData                             0x00007fff9112cea8 -[NSSQLCore objectsForFetchRequest:inContext:] + 520
7   CoreData                             0x00007fff9112c90b -[NSSQLCore executeRequest:withContext:error:] + 299
8   CoreData                             0x00007fff911e1389 __65-[NSPersistentStoreCoordinator executeRequest:withContext:error:]_block_invoke + 3945
9   CoreData                             0x00007fff911eb5ab gutsOfBlockToNSPersistentStoreCoordinatorPerform + 171
10  libdispatch.dylib                    0x00007fff8eb62c13 _dispatch_client_callout + 7
11  libdispatch.dylib                    0x00007fff8eb63e5e _dispatch_barrier_sync_f_invoke + 56
12  CoreData                             0x00007fff911da5a2 _perform + 194
13  CoreData                             0x00007fff9112c5a5 -[NSPersistentStoreCoordinator executeRequest:withContext:error:] + 533
14  CoreData                             0x00007fff9112adfb -[NSManagedObjectContext executeFetchRequest:error:] + 587
15  AppKit                               0x00007fff91ddd745 -[_NSManagedProxy fetchObjectsWithFetchRequest:error:] + 69
16  AppKit                               0x00007fff91c1aacc -[NSArrayController(NSManagedController) _performFetchWithRequest:merge:error:] + 62
17  AppKit                               0x00007fff91ddcdc3 -[NSObjectController(NSManagedController) fetchWithRequest:merge:error:] + 176
18  Contacts Journal CRM                 0x000000010d0d8eb2 -[ContactsListDisplaySource refetchArrayController] (ContactsListDisplaySource.m:57)
19  Contacts Journal CRM                 0x000000010d0d8e6e -[ContactsListDisplaySource awakeFromNib] (ContactsListDisplaySource.m:47)
20  CoreFoundation                       0x00007fff8c736bdf -[NSSet makeObjectsPerformSelector:] + 223
21  AppKit                               0x00007fff917b214d -[NSIBObjectData nibInstantiateWithOwner:options:topLevelObjects:] + 1216
22  AppKit                               0x00007fff9198ca0e -[NSNib _instantiateNibWithExternalNameTable:options:] + 677
23  AppKit                               0x00007fff9198c65e -[NSNib _instantiateWithOwner:options:topLevelObjects:] + 143
24  AppKit                               0x00007fff9198b957 -[NSViewController loadView] + 272
25  AppKit                               0x00007fff9190af03 -[NSViewController _loadViewIfRequired] + 75
26  AppKit                               0x00007fff9190ae6d -[NSViewController view] + 30
27  Contacts Journal CRM                 0x000000010d021078 -[AppDelegate displayVC:] (AppDelegate.m:496)
28  Contacts Journal CRM                 0x000000010d020ff8 -[AppDelegate changeViewControllersWithIndex:] (AppDelegate.m:414)
29  Contacts Journal CRM                 0x000000010d01edb6 -[AppDelegate postApplicationDidFinishLaunchingWithNotification:] (AppDelegate.m:130)
30  Contacts Journal CRM                 0x000000010d01ec00 -[AppDelegate applicationWillFinishLaunching:] (AppDelegate.m:114)
31  CoreFoundation                       0x00007fff8c7e645c __CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__ + 12
32  CoreFoundation                       0x00007fff8c6d6634 _CFXNotificationPost + 3140
33  Foundation                           0x00007fff8f33d9d1 -[NSNotificationCenter postNotificationName:object:userInfo:] + 66
34  AppKit                               0x00007fff9180cf57 -[NSApplication finishLaunching] + 440
35  AppKit                               0x00007fff9180ca21 -[NSApplication run] + 128
36  AppKit                               0x00007fff91789354 NSApplicationMain + 1832
37  libdyld.dylib                        0x00007fff8d0cd5c9 start + 1
Z S
  • 7,039
  • 12
  • 53
  • 105
  • 1
    You're using `fetchWithRequest` rather than `fetch.` I'd suspect that the core data stack just isn't spun up for some users, and `fetchWithRequest` catches it with its pants down. Maybe. – stevesliva Apr 29 '15 at 23:55
  • 1
    What's the difference between the two? I thought that they were mostly the same; you could just specify a fetchRequest with one and not the other and that was the only difference (other than maybe fetchWithRequest can be subclasses, but not sure how that makes a difference here) – Z S Apr 30 '15 at 04:56
  • 4
    Fetch is scheduled on the run loop queue, the method you use is immediate – stevesliva Apr 30 '15 at 05:23
  • 1
    I believe @stevesliva is correct - I think you need to be using -fetch:. -fetchWithRequest:... is meant for subclassers to customize a fetch request. – Joshua Nozzi Apr 30 '15 at 21:19
  • 1
    Following up on this after a while, but I have found that using `fetch:` doesn't work ... it doesn't load any objects in the array controller. This code is called in awakeFromNib, so that might be the problem (and why I was using `fetchWithRequest`) according to this SO link: http://stackoverflow.com/questions/5002258/how-do-you-populate-a-nsarraycontroller-with-coredata-rows-programmatically – Z S Jun 02 '15 at 12:26

1 Answers1

0

You might think this is really basic, but maybe you could try this:

    [_peopleArrayController.managedObjectContext performBlockAndWait:
^{
    [_peopleArrayController fetchWithRequest:nil merge:NO error:&error];
}];

I've found that using the managedObjectContext's performBlock: and performBlockAndWait: methods when using core data prevents hangs in my apps. Just check out the NSManagedObjectContext class reference https://developer.apple.com/library/ios/documentation/Cocoa/Reference/CoreDataFramework/Classes/NSManagedObjectContext_Class/

simple_code
  • 707
  • 9
  • 24