2011-07-22 127 views
3

我的核心數據模型就不會保存。我可以插入一種對象(圖 - 見下文),並保存將工作。我可以添加這種對象的多個副本,並保存將工作。當我插入一個不同的對象,任何一個失敗的話,通常與這樣的:核心數據EXC_BAD_ACCESS失敗上保存?

#2 0x00007fff86c342c8 in -[NSManagedObjectContext(_NSInternalAdditions) _changeIDsForManagedObjects:toIDs:]() 

其他對象並不複雜:只是字符串和數值。它們的值設定爲節省時間。我已經減少了程序的NSPersistentDocument只是初始化:以下是稱爲initWithType:error:在我NSPersistentDocument子類中的相關代碼:

... 

// Disable undo registration before inserting default objects 
[[[self managedObjectContext] undoManager] disableUndoRegistration]; 

// Insert the root graph 
self.root = [NSEntityDescription insertNewObjectForEntityForName:@"Graph" inManagedObjectContext:[self managedObjectContext]]; 
self.root.createdDate = [NSDate date]; 
self.root.lastModifiedDate = [NSDate date]; 
self.root.name = @"Untitled Model"; 
self.root.colour = [NSColor colorWithDeviceRed:0.6 green:0.6 blue:0.6 alpha:1.0]; 

// Insert default drawing parameters 
// fails when including this line 
self.drawing = [NSEntityDescription insertNewObjectForEntityForName:@"Drawing" inManagedObjectContext:[self managedObjectContext]]; 

[[self managedObjectContext] processPendingChanges]; 
[[[self managedObjectContext] undoManager] enableUndoRegistration]; 

... 

運行時,我得到:

2011-07-23 07:46:58.012 Z2[15774:a0f] Managed Object Context: <NSManagedObjectContext: 0x2000c65e0> 
2011-07-23 07:46:58.013 Z2[15774:a0f] Persistent Store Coordinator: <NSPersistentStoreCoordinator: 0x200063700> 
2011-07-23 07:46:58.013 Z2[15774:a0f] Entity: Graph 
...<full Entity list> 
2011-07-23 07:46:58.016 Z2[15774:a0f] Entity: Drawing 
2011-07-23 07:46:58.018 Z2[15774:a0f] Object: <Graph: 0x20004e220> (entity: Graph; id: 0x20003e400 <x-coredata:///Graph/t527187E0-DC67-4A9E-BA88-67A4CD3445222> ; data: { 
colour = "(...not nil..)"; 
createdDate = "2011-07-22 21:46:54 +0000"; 
errorString = nil; 
firstDate = nil; 
lastDate = nil; 
lastModifiedDate = "2011-07-22 21:46:54 +0000"; 
lines = (); 
name = "Untitled Model"; 
nodes = (); 
profiles = (); 
test = 0; 
warningString = nil; 
}) 
2011-07-23 07:46:58.019 Z2[15774:a0f] Object: <Drawing: 0x20004f140> (entity: Drawing; id: 0x200062280 <x-coredata:///Drawing/t527187E0-DC67-4A9E-BA88-67A4CD3445223> ; data: { 
centrex = 0; 
centrey = 0; 
textSize = 12; 
typeface = "Helvetica Neue"; 
zoomFactor = 1; 
}) 
Program received signal: 「EXC_BAD_ACCESS」. 

每個實體都有它自己的類NSManagedObject的子類。每個屬性都被定義爲一個動態屬性。每個屬性都有一個默認值,這是合理的。

我看到其他人認爲過度釋放這種類型的問題,但我不進行保留,並在核心數據代碼的任何地方釋放。在Graph對象之後選擇插入哪個實體並不重要;他們都失敗了。

核心數據的工作是由一個框架(圖)來完成。該框架是從基於文檔的應用程序(Z)調用的,該應用程序將框架的文檔創建對象劃分爲子類。

下面是保存面板末端的堆棧跟蹤:

Program received signal: 「EXC_BAD_ACCESS」. 
sharedlibrary apply-load-rules all 
(gdb) bt 
#0 0x00007fff80352480 in CFDictionarySetValue() 
#1 0x00007fff86c0b2ed in _PFCMT_SetValue() 
#2 0x00007fff86c342c8 in -[NSManagedObjectContext(_NSInternalAdditions) _changeIDsForManagedObjects:toIDs:]() 
#3 0x00007fff86c44b2b in -[NSSQLCore commitChanges:]() 
#4 0x00007fff86c3926e in -[NSSQLCore saveChanges:]() 
#5 0x00007fff86bfcc8b in -[NSSQLCore executeRequest:withContext:]() 
#6 0x00007fff86bfc051 in -[NSPersistentStoreCoordinator(_NSInternalMethods) executeRequest:withContext:]() 
#7 0x00007fff86c3in -[NSManagedObjectContext save:]() 
#8 0x00007fff8144179d in -[NSPersistentDocument writeToURL:ofType:forSaveOperation:originalContentsURL:error:]() 
#9 0x0000000100020460 in -[GraphDocument writeToURL:ofType:forSaveOperation:originalContentsURL:error:] (self=0x2000c4be0, _cmd=0x7fff816eb6ce, absoluteURL=0x20004eec0, typeName=0x20000ea80, saveOperation=1, absoluteOriginalContentsURL=0x0, outError=0x7fff5fbfe308) at /<path to>/GraphDocument.m:380 
#10 0x00000001000010bc in -[ZDocument writeToURL:ofType:forSaveOperation:originalContentsURL:error:] (self=0x2000c4be0, _cmd=0x7fff816eb6ce, absoluteURL=0x20004eec0, typeName=0x20000ea80, saveOperation=1, absoluteOriginalContentsURL=0x0, outError=0x7fff5fbfe308) at /<path to>/ZDocument.m:110 
#11 0x00007fff81316bd2 in -[NSDocument _writeSafelyToURL:ofType:forSaveOperation:error:]() 
#12 0x00007fff81315fd0 in -[NSDocument writeSafelyToURL:ofType:forSaveOperation:error:]() 
#13 0x00007fff814406dc in -[NSPersistentDocument writeSafelyToURL:ofType:forSaveOperation:error:]() 
#14 0x00007fff81311356 in -[NSDocument saveToURL:ofType:forSaveOperation:error:]() 
#15 0x00007fff81314404 in -[NSDocument _saveToURL:ofType:forSaveOperation:delegate:didSaveSelector:contextInfo:]() 
#16 0x00007fff81311637 in -[NSDocument saveToURL:ofType:forSaveOperation:delegate:didSaveSelector:contextInfo:]() 
#17 0x00007fff8131377c in -[NSDocument _savePanelWasPresented:withResult:inContext:]() 
#18 0x00007fff8148335e in -[NSSavePanel _didEndSheet:returnCode:contextInfo:]() 
#19 0x00007fff81227d45 in -[NSApplication endSheet:returnCode:]() 
+0

你可以插入一個'Drawing'對象,如果你不先插入一個'Graph'對象? – TechZen

+0

你是否停止了所有例外?我想知道是否在您獲得EXC_BAD_ACCESS之前發生錯誤。 – paulmelnikow

回答

0

因爲它沒有對對象ID的變化,我會想這個問題是一個關係。最可能的問題是所需的關係,刪除規則或驗證。

+0

某些實體與任何其他實體無關。有沒有刪除規則和驗證僅限於什麼的IDE:對數字最大值,最小值和默認值,在琴絃上沒有驗證。 – Conbobulate