Open evanmiller opened 4 years ago
Sorry, I wanted to look at this today but was dealing with a sewer issue in our house :|
It looks as though you have figured this out, and having -close check _closing as you suggest is indeed what I would do, so it looks like a simple 2-line fix, well, 4 lines if you count curly bracket lines. Please submit a pull request if you want, or I shall get to it next week.
Well, I'm not sure the flag would fix it - the entry point on the second call to close
is the subclass, so it looks like the subclass would have to check the flag.
Relevant discussion: https://stackoverflow.com/questions/5627267/nsdocument-subclass-close-method-called-twice
Maybe not worth fixing, or impossible to fix on the BSManagedDocument side.
Closing issue since I think that double-close is just a fact of life when working with NSDocument
Life has many interesting facts when NSDocument becomes a part of it :)) So I presume this means you are modifying your subclass to tolerate the second close.
Indeed, this is what I do, for that very reason. I override -close
to set a flag and call my finicky "tear down" code only during the first call. Also, my code comments notes that I discovered a few months ago, testing with macOS 10.15.4, that executing the following AppleScript:
tell application "BookMacster" to close every document
indeed causes -close
to be called twice.
I'm working through some customer issues / crashes that are being triggered because
close
is calling itself. To be clear, this is interacting with some bugs in my own code, but I think it's safe to say thatclose
should only occur once.Here's the relevant part of backtrace I'm looking at:
In my code
[CKMapDocument close]
calls[super close]
(see lines 6 and 7 above). But this ends up triggering another close event after the window is closed.I will note that I only see this behavior after turning off autosaving / restorable windows in System Preferences (i.e. checking the boxes "Ask to keep changes when closing documents" and "Close windows when quitting an app") but with autosaving turned on in the code (
autosavesInPlace
returnsYES
). The crash occurs when attempting to quit the application with an edited document open, as you may have surmised from the backtrace.I can add a workaround on my end, but I believe there should be some logic added to
closeNow
to check the_closing
flag before initiating another close.