Crash as NSPersistentDocument creates its persistence stack
Crash as NSPersistentDocument creates its persistence stack
- Subject: Crash as NSPersistentDocument creates its persistence stack
- From: Jerry Krinock <email@hidden>
- Date: Tue, 23 Dec 2008 16:44:03 -0800
This morning I was working on some code in my Core Data document-based
project, and upon testing I found it now crashes whenever I open a new
or existing document. I backed out all the changes, cleaned with
dependencies and precompiled headers, restarted -- still no good.
So I over-rode -
configurePersistentStoreCoordinatorForURL:ofType:modelConfiguration:storeOptions:error
:, just to add some NSLogs. I found that, when opening an existing
document, the crash occurs when I invoke super in this method,
although it's not quite repeatable -- The dreaded "[Session
started..." from gdb often logs between the output from two
consecutive NSLog statements [1]. Maybe coming from another thread?
Here's top of the stack trace [2]:
#0 0x9549e688 in objc_msgSend
#1 0x90223f0d in -[NSPersistentStoreCoordinator
addPersistentStoreWithType:configuration:URL:options:error:]
#2 0x91142fe9 in -[NSPersistentDocument
configurePersistentStoreCoordinatorForURL:ofType:modelConfiguration:storeOptions:error
:]
The behavior is similar with an existing document -- it crashes in
initWithType:error:, upon invocation of
insertNewObjectForEntityForName:inManagedObjectContext:, plus or minus
3 lines of code.
I'd thought that maybe my .xcdatamodel got corrupt (there is only
one), but I haven't touched that file in 3 days. I open it up and it
looks pretty. All the lines are straight and the text is crisp.
The NSPersistentDocument documentation doesn't give much detail --
"... an NSPersistenDocument creates its own ready-to-use persistence
stack". I presume that it uses -mergedModelFromBundles:?
If anyone has any ideas what I should beat on, I'll let you know how
it works!
Thanks,
Jerry Krinock
[1] For example, the following code in my NSPersistentDocument subclass:
- (BOOL)configurePersistentStoreCoordinatorForURL:(NSURL *)url
ofType:(NSString *)fileType
modelConfiguration:(NSString
*)configuration
storeOptions:(NSDictionary
*)storeOptions
error:(NSError **)error_p {
NSLog(@"DebugLog: 3818 configuring psc") ;
NSLog(@"DebugLog: 3818 url: %@", url) ;
NSLog(@"DebugLog: 3818 fileType: %@", fileType) ;
NSLog(@"DebugLog: 3818 configuration: %@", configuration) ;
NSLog(@"DebugLog: 3818 storeOptions: %@", storeOptions) ;
[super configurePersistentStoreCoordinatorForURL:url
ofType:fileType
modelConfiguration:configuration
storeOptions:storeOptions
error:error_p] ;
NSLog(@"DebugLog: 3818 done ") ;
return YES ;
}
Produces this log output:
BkmmApp [3327:10b] DebugLog: 3818 configuring psc
BkmmApp [3327:10b] DebugLog: 3818 url: file://localhost/Users/jk/Desktop/My4thDoc.bmxbk
BkmmApp [3327:10b] DebugLog: 3818 fileType: Bkmm Book
BkmmApp [3327:10b] DebugLog: 3818 configuration: (null)
[Session started at 2008-12-23 16:15:32 -0800.]
BkmmApp [3327:10b] DebugLog: 3818 storeOptions: (null)
Loading program into debugger…
By the way, the (null) configuration and storeOptions values appear to
be normal since I see the same nulls when I put this code into the
Apple Sample Code project DepartmentsAndEmployees, and it does not
crash.
[2] Here is the whole stack trace of the crash, when opening an
existing document
#0 0x9549e688 in objc_msgSend
#1 0x90223f0d in -[NSPersistentStoreCoordinator
addPersistentStoreWithType:configuration:URL:options:error:]
#2 0x91142fe9 in -[NSPersistentDocument
configurePersistentStoreCoordinatorForURL:ofType:modelConfiguration:storeOptions:error
:]
#3 0x00038d10 in -[BmxBk
configurePersistentStoreCoordinatorForURL:ofType:modelConfiguration:storeOptions:error
:] at BmxBk.m:147
#4 0x91143fab in -
[NSPersistentDocument(NSPersistentDocumentDeprecated)
configurePersistentStoreCoordinatorForURL:ofType:error:]
#5 0x911433b6 in -[NSPersistentDocument readFromURL:ofType:error:]
#6 0x90f3e6c6 in -[NSDocument initWithContentsOfURL:ofType:error:]
#7 0x90f0e274 in -[NSDocumentController
makeDocumentWithContentsOfURL:ofType:error:]
#8 0x90f0d898 in -[NSDocumentController
openDocumentWithContentsOfURL:display:error:]
#9 0x91070fc7 in -[NSDocumentController(NSInternal) _openFile:]
#10 0x90f8216a in -[NSApplication _doOpenFile:ok:tryTemp:]
#11 0x90fc4f8a in -[NSApplication openFile:ok:]
#12 0x91070330 in -[NSDocumentController(NSPrivate)
_openRecentDocument:]
#13 0x90cfe53b in -[NSApplication sendAction:to:from:]
#14 0x90dad17c in -[NSMenu performActionForItemAtIndex:]
#15 0x90dace81 in -[NSCarbonMenuImpl
performActionWithHighlightingForItemAtIndex:]
#16 0x90d89b5a in AppKitMenuEventHandler
#17 0x93317143 in DispatchEventToHandlers
#18 0x9331657d in SendEventToEventTargetInternal
#19 0x93332ed2 in SendEventToEventTarget
#20 0x9336723d in SendHICommandEvent
#21 0x9338da8f in SendMenuCommandWithContextAndModifiers
#22 0x9338da4c in SendMenuItemSelectedEvent
#23 0x9338d95e in FinishMenuSelection
#24 0x9336a4ec in MenuSelectCore
#25 0x93369ed7 in _HandleMenuSelection2
#26 0x93369d4b in _HandleMenuSelection
#27 0x90cc650b in _NSHandleCarbonMenuEvent
#28 0x90c2d26a in _DPSNextEvent
#29 0x90c2c630 in -[NSApplication
nextEventMatchingMask:untilDate:inMode:dequeue:]
#30 0x90c2566b in -[NSApplication run]
#31 0x90bf28a4 in NSApplicationMain
#32 0x00003177 in main at BkmmApp-Main.m:22
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden