-
Notifications
You must be signed in to change notification settings - Fork 25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Document wont open if saved during opening #22
Comments
My suspicion is that you've got a deadlock here. I imagine opening the document takes a lock on the file (using If so, your problem here is independent of Are you able to confirm the deadlock from pausing in the debugger? |
Thanks for your answer. I don't know what's a deadlock. How can I see it in the debugger? |
If you don't know what a deadlock is, I suggest now is the time to improve your Computer Science knowledge and read up on the topic :-) |
Yes... learning, learning, learning... I imagine it's a lock and someone has lost the key ;-) |
How can I see it in the debugger? |
I'm assuming the symptom is: your document never appears on-screen. If so, after waiting a little, hit pause in Xcode. You should then be able to see the stack of all active threads. I imagine one of those will be deadlocked inside |
Drag the slider to see the full trace |
At the bottom of the navigator view, there is a slider, which you can drag to expose more of the stack trace |
Some possible solutions then:
|
For information, I tried to subclass - (void)openDocumentWithContentsOfURL:(NSURL *)url
display:(BOOL)displayDocument
completionHandler:(void (^)(NSDocument *, BOOL, NSError *))completionHandler
{
[super openDocumentWithContentsOfURL:url
display:displayDocument
completionHandler:^void (NSDocument * theDoc, BOOL aBool, NSError * error)
{
completionHandler(theDoc, aBool, error) ;
/*
We save synchronously
*/
dispatch_sync(dispatch_get_main_queue(), ^
{
[theDoc saveDocument:self] ;
}) ;
}] ;
} as well as - (id)makeDocumentWithContentsOfURL:(NSURL *)url
ofType:(NSString *)typeName
error:(NSError *__autoreleasing *)outError
{
Document * loadedDoc = [super makeDocumentWithContentsOfURL:url
ofType:typeName
error:outError] ;
/*
We save synchronously
*/
dispatch_sync(dispatch_get_main_queue(), ^
{
[loadedDoc saveDocument:self] ;
}) ;
return loadedDoc ;
} but both still create a deadlock. |
When a document is opened, sometimes some corrupted data needs to be fixed. I do it, but I want to save these fixes. So that the user won't remark anything. |
I suspect your
|
Hi Mike, First of all, thank you for helping me. I know you don't have to do this (and it is not related to I agree with you, this is completely independent of To answer you remarks:
|
It's important to make the distinction: those stack traces you've posted are an exception, not a crash |
Hi Mike!
I find this bug or feature (?).
During the opening of a document, I do some stuff and then save the document (with
saveDocument:
): the document won't open.Here is a minimal example:
and
With this class, do the following:
It won't open.
Here is the context of my question.
Shall I use the
saveDocument:
method? If I[self.managedObjectContext save:NULL]
, is it enough for the document to be saved? (my doc is not a bundle)(The problem for
NSDocument
is that if you[self.managedObjectContext save:NULL]
thenNSDocument
will complain about another app having modified the document since the last save).Thanks.
The text was updated successfully, but these errors were encountered: