Andrew
Andrew

Reputation: 16051

App quitting on [managedObjectContext save:] without an error

My code performs a number of tasks using core data, and then when I go to save, it crashes without any error. My code for the save is simply:

[[self managedObjectContext] save:&error];

NSLog(@"Error: %@", error);

It doesn't reach the error line, it's crashed and quit to home screen by that point.

I have everything other than 'Guard Malloc' selected in Diagnostics.

This is the log I get when it runs the save command:

CoreData: sql: BEGIN EXCLUSIVE
CoreData: sql: SELECT Z_MAX FROM Z_PRIMARYKEY WHERE Z_ENT = ?
CoreData: sql: UPDATE Z_PRIMARYKEY SET Z_MAX = ? WHERE Z_ENT = ? AND Z_MAX = ?
CoreData: sql: COMMIT
CoreData: sql: BEGIN EXCLUSIVE
CoreData: sql: INSERT INTO ZENTRY(Z_PK, Z_ENT, Z_OPT, ZLOCATION, ZBOOKMARKED, ZCREATIONDATE, ZENTRYID, ZMESSAGE, ZSECTIONIDENTIFIER, ZTICDSSYNCID, ZVERSION) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
CoreData: sql: COMMIT
CoreData: sql: pragma page_count
CoreData: annotation: sql execution time: 0.0047s
CoreData: sql: pragma freelist_count
CoreData: annotation: sql execution time: 0.0069s

There is no mention of any error before this. How can I get some indication of what's crashing my app?

EDIT: I now know this happens after a call to [NSEntityDescription insertNewObjectForEntityForName:@"Entry" inManagedObjectContext:[self managedObjectContext]]; and that it's caused by a method performed on my core data store by TICoreDataSync before this. I can't change that code, or remove it from working with my core data store. I think it's a problem to do with the store being accessed on multiple threads, so now I need to know how to deal with that, on the main thread?

Upvotes: 0

Views: 282

Answers (1)

David Hoerl
David Hoerl

Reputation: 41632

Obviously the MOC is corrupted. Is it being accessed from multiple threads?

What I would do is, with every change (where moc is saveable - consistent), attempt a save. The place where the corruption happens will crash, so you now know at least more or less where the problem is.

I do this in my app - in fact all dev build save constantly, only Deployment and QA builds have this turned off. I've found many many bugs this way. Wrap the saves in some if flag statements or write a macro.

Upvotes: 3

Related Questions