保存时出现错误时Core Data崩溃:从函数调用_Unwind_Resume - 图像CoreData中的[NSSQLCore performChanges]

时间:2022-01-16 07:26:58

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 that 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.

然后,用户可以搜索其他部门和/或员工。例如,当他们为艺术部门进行搜索时,服务器会返回该部门的前20名员工。代码将新部门存储到核心数据中,并将员工存储到核心数据中。我使用2个线程,一个用于将数据存储到上下文中的实际工作,另一个用于在GUI上显示数据。我使用mergeChangesFromContextDidSaveNotification方法来合并更改。

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.

总是导致_unwind_resume错误。我从这里接受了建议。关闭Ob​​jective C异常。我看到这个调用堆栈。

#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.

我通过在保存之前将其打印出来看看我试图保存的数据,看起来没问题。通常有1或2名员工已经导入,并且会更新(根据需要),并插入其他员工。导入上下文似乎正确地看到了。

I also checked to make sure that the datamodel doesn't have invalid non-optional attributes.

我还检查了以确保datamodel没有无效的非可选属性。

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.

那么现在,我有点陷入下一步的尝试?任何建议将不胜感激。

2 个解决方案

#1


0  

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.

我很确定_Unwind_Resume是异常处理堆栈的一部分。所以,它真的告诉你的是系统无法处理的异常。

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

我会评论您在managedObjects上可能有的任何保留和释放,尤其是您可能标记为自动释放的任何保留和释放。错误管理版本可能导致未保存的托管对象从对象图中消失,从而创建一个w

#2


0  

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.

好吧,看起来很奇怪,我认为问题是数据模型中的类型与实际数据不匹配。在数据模型中,我将其中一个字段错误地定义为Int32,实际上它应该是一个浮点数。

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!

希望错误消息不那么透明!

#1


0  

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.

我很确定_Unwind_Resume是异常处理堆栈的一部分。所以,它真的告诉你的是系统无法处理的异常。

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

我会评论您在managedObjects上可能有的任何保留和释放,尤其是您可能标记为自动释放的任何保留和释放。错误管理版本可能导致未保存的托管对象从对象图中消失,从而创建一个w

#2


0  

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.

好吧,看起来很奇怪,我认为问题是数据模型中的类型与实际数据不匹配。在数据模型中,我将其中一个字段错误地定义为Int32,实际上它应该是一个浮点数。

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!

希望错误消息不那么透明!