Re: Why would a view be asked to draw after its window has been ordered out?
Re: Why would a view be asked to draw after its window has been ordered out?
- Subject: Re: Why would a view be asked to draw after its window has been ordered out?
- From: James Walker <email@hidden>
- Date: Thu, 13 Dec 2018 16:40:33 -0800
On 12/13/18 1:35 PM, Rob Petrovec wrote:
On Dec 13, 2018, at 2:26 PM, James Walker <email@hidden> wrote:
On 12/13/18 11:05 AM, Matt Jacobson wrote:
The buffered nature of the Mac OS X window system means that windows can
“display” (i.e., go through the process of updating) even when ordered out.
Ordered-out windows /can/ occasionally be seen on screen (consider App Exposé,
which shows minimized windows, or Show All Tabs in apps using NSWindow
tabbing), and the system may snapshot or display ordered-out windows for
various reasons at other times, too.
In general, I’d say: you should not /rely/ on the fact that ordered-out windows
are displayed—in the future, the system might choose to defer it as an
optimization—but neither should you expect it not to happen.
Simply bailing out of -drawRect: (which, incidentally, is called on /views/,
not windows) seems like a bad idea, since the window may display into an
invalid state, which could result in corruption. I’d instead investigate the
underlying cause of the crash, which may result from your view attempting to
use an object that it does not hold a strong (or weak-upgraded-to-strong)
reference to.
The view was using a C++ object that had been destroyed during closing of my
document. I'm afraid that if I start playing with the order of destruction,
I'm likely to break something else. But I can be more precise about when I
decline to draw, by having my document post a notification when it starts to
shut down.
If it’s a C++ object then reference it in your view with a weak_ptr so
you can tell when/if it has been disposed of.
Oh, cool! I didn't get around to using C++11 until about a year ago
(yes, I'm behind the curve), and I read a number of "what's new in
C++11" web pages, but somehow I missed std::weak_ptr.
On Dec 13, 2018, at 10:44 AM, James Walker <email@hidden
<mailto:email@hidden>> wrote:
I was getting a crash on quit resulting from a drawRect: method being called on
a window that had been ordered out. I can solve the immediate problem just by
bailing out of drawRect: if the window is invisible, but I wish I understood
what's going on. The call stack shows a run loop observer calling
CA::Transaction::commit() resulting in -[NSWindow displayIfNeeded] being
called, but I don't know why displayIfNeeded would do anything with an
invisible window.
_______________________________________________
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
_______________________________________________
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