On 2011 Aug 01, at 08:14, Kevin Perry wrote:

> Canceling an autosave when -autosavingIsImplicitlyCancellable returns NO will 
> cause problems with file coordination.

Thank you, Kevin.  I believe you and Jens on this.  Indeed, when I close a 
document window, its document receives a 
saveToURL:ofType:forSaveOperation:completionHandler: message, and, as expected, 
-autosavingIsImplicitlyCancellable returns NO.

> If you absolutely cannot save when a non-cancellable autosave starts, it is 
> OK to defer the autosave until you're ready, as long as you make sure to call 
> the original completionHandler when you're done.

Makes sense, but I'm getting a crash if I begin some operations and then hit 
the 'close' button on the window while the operations are in progress…

I take the four parameters I receive in 
saveToURL:ofType:forSaveOperation:completionHandler: and put them into a 
dictionary in an NSOperation, and throw this operation onto the end my 
operation queue.  (This project was written back in 10.5 so it does not use 
GCD.)  

When this final operation runs, I send this dictionary to a selector on the 
main thread.  But the completion handler seems to contain a bomb at this point 
– it usually crashes upon receiving any message, not always in the same place.  
Often, it crashes when I send it to super's 
saveToURL:ofType:forSaveOperation:completionHandler:, which apparently tries to 
copy it, like this…

#0      0x97c68987 in _Block_copy_internal
#1      0x97c68bd8 in _Block_object_assign
#2      0x97123a41 in __copy_helper_block_138
#3      0x97c67f86 in _Block_call_copy_helper
#4      0x97c689d3 in _Block_copy_internal
#5      0x97c68bd8 in _Block_object_assign
#6      0x9713f43b in __copy_helper_block_40
#7      0x97c67f86 in _Block_call_copy_helper
#8      0x97c689d3 in _Block_copy_internal
#9      0x9bb22eae in _dispatch_Block_copy
#10     0x9bb251ea in dispatch_async
#11     0x9713ac9c in -[NSDocument performAsynchronousFileAccessUsingBlock:]
#12     0x97123688 in -[NSDocument 
saveToURL:ofType:forSaveOperation:completionHandler:]

Retaining the completionHandler a half dozen times, with no corresponding 
releases, before placing into the dictionary, does not help.  So apparently 
it's not memory management.

I also get a crash if I instead save using the old-fashioned method, and then 
invoke the completion handler "manually"…

    NSError* error = nil ;
    BOOL ok = [super saveToURL:url
                        ofType:typeName
              forSaveOperation:saveOperation
                         error:&error] ;
    completionHandler(error) ;

In this case, the saveToURL:::: completes successfully, but it crashes when I 
invoke the completion handler.

So I tried just forgetting the completion handler, commenting out that last 
line, but then I get a crash later, it looks like, when the dictionary is 
deallocced and the completion handler gets a CFRelease().

Finally, I tried just forgetting the completion handler, not even entering it 
into the dictionary. No crash.  However, as you predicted…

> your application be blocked until the completionHandler is called

I wasn't sure what you meant by that, since the main thread is not blocked.  
Actually, I can continue editing the document.  However it hangs if I later try 
to close the document…

#0      0x995d5c5e in semaphore_wait_trap
#1      0x9bb26874 in _dispatch_semaphore_wait_slow
#2      0x9bb26970 in dispatch_semaphore_wait
#3      0x9713b135 in -[NSDocument 
performActivityWithSynchronousWaiting:usingBlock:]
#4      0x97126cf4 in -[NSDocument 
canCloseDocumentWithDelegate:shouldCloseSelector:contextInfo:]
#5      0x0018aca3 in -[MyDocument continueCanCloseWithInfo:] at 
MyDocument.m:456

or save the document…

#0      0x995d5c5e in semaphore_wait_trap
#1      0x9bb26874 in _dispatch_semaphore_wait_slow
#2      0x9bb26970 in dispatch_semaphore_wait
#3      0x9713b135 in -[NSDocument 
performActivityWithSynchronousWaiting:usingBlock:]
#4      0x971205cd in -[NSDocument 
saveDocumentWithDelegate:didSaveSelector:contextInfo:]
#5      0x971201e0 in -[NSDocument saveDocument:]
#6      0x00186755 in -[MyDocument saveDocumentFinalAsAs:] at MyDocument.m:1651

What could it be about this completion handler object that causes it to become 
a bomb after sitting in a dictionary for a few seconds?

Thank you,

Jerry

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to