Core Data crash when saving with error : _Unwind_Resume called from function -[NSSQLCore performChanges] in image CoreData
I am a bit stuck on this core data error. My basic setup on the app is to load some basic data at initialization. Lets call them Department and Employees. At initialization, I would only load the departments and employees related to the current user of the app.
Then the user has the ability to search for other department and/or employees. When they do a search, for example, for the Arts department, the server returns the first 20 employees from t开发者_运维技巧hat department. The code stores the new department into core data, and also stores the employees into core data. I am using 2 threads, one to the actual work of storing the data into the context, and the other to show the data on the GUI. I use the mergeChangesFromContextDidSaveNotification method to merge the changes.
The storing of the department always works, but the line :
BOOL ok = [importContext save:&errorSave];
always causes the _unwind_resume error. I've taken the advice from here. Turned on stop on Objective C exceptions. And I see this call stack.
#0 0x030203f4 in objc_exception_throw ()
#1 0x0253d921 in -[NSSQLiteConnection updateRow:] ()
#2 0x0253c6b4 in -[NSSQLConnection performAdapterOperations:] ()
#3 0x0253c35e in -[NSSQLCore _performChangesWithAdapterOps:] ()
#4 0x0253ae3a in -[NSSQLCore performChanges] ()
#5 0x02534778 in -[NSSQLCore saveChanges:] ()
#6 0x024f27c9 in -[NSSQLCore executeRequest:withContext:error:] ()
#7 0x025a134b in -[NSPersistentStoreCoordinator executeRequest:withContext:error:] ()
#8 0x0252b088 in -[NSManagedObjectContext save:] ()
Which doesn't give me any clue on why the save is causing this exception.
I had a look at the data I am trying to save by printing it out just before the save and it looks ok. There are usually 1 or 2 employees that have already been imported, and they are updated (as required), and the other employees are inserted. The import context seems to see that correctly.
I also checked to make sure that the datamodel doesn't have invalid non-optional attributes.
I thought the problem might be due to threading, so I've moved everything to the same thread, just to check. Nope, problem still there.
So now, I am a bit stuck on what to try next? Any suggestions would be greatly appreciated.
I'm pretty sure _Unwind_Resume
is part of the exception handling stack. So, really all it tells you is that an exception occurred that the system couldn't handle.
I would comment any retains and releases you might have on managedObjects, especially any you may have marked as autorelease
. Mismanaging release can cause an unsaved managedObject to disappear from the object graph creating a w
Ok, strange as it seems, I think the issue was a mis-match of types in the datamodel and the actual data. in the data model, I defined one of the fields incorrectly as Int32, where in actual fact it should have been a float.
Although I don't fully understand why on the first save it always works, but the second time i try to save, I get the above error.
With the data type change, now, multiple saves works as expected.
Wish the error message was a little less opaque!
精彩评论