Post by Andrew TrevorrowPost by Stefan CsomorI've changed the code of wxNonOwnedWindow::Update to avoid this by
throttling to 30 Hz
void wxNonOwnedWindow::Update()
{
if ( clock() - s_lastFlush > CLOCKS_PER_SEC / 30 )
{
s_lastFlush = clock();
m_nowpeer->Update();
}
}
I'd also like to request that the above throttling code be removed.
It's quite unnecessary and can break apps that want to do immediate
Update() calls in certain cases.
That guard is not at all unnecessary, I wouldn't have written it
otherwise.
It's unnecessary because the Mac OS automatically throttles update
calls that occur faster than the refresh rate (as mentioned in the
Tech Note you referred to in your next post).
Our app *relied* on that automatic throttling, so the guard code
you've added has now changed our app's behavior (for the worse).
See below for details.
The problem was that some apps are calling Update too
frequently - so that - without that patch - Update effectively throttles
them down to a crawl (perhaps 60 Hz of Update calls or so), because the
underlying Flush is blocking until the next OS refresh is taking place.
I'm not sure why you think 60Hz of updates is a crawl! If it's a
problem for some apps then they should be modified to do their own
update throttling. By modifying the behavior of wxWindow::Update()
you are changing the behavior of apps (like ours) that want it to do
exactly what the wx docs say: "immediately repaint the invalidated
area of the window". At the very least, it's inconsistent to have
Mac apps behave differently.
But maybe we can find a better solution for that congestion problem. Are
you using the Carbon or the Cocoa build ?
We currently do both: a Carbon build for Mac OS 10.4/5 and a Cocoa build
for 10.6+, but we'll probably drop the Carbon build in the next release.
And what exactly needs immediate update ?
Our app is a cellular automata simulator (Conway's Game of Life is
the best known example), so it needs to display pattern sequences
at various user-adjustable rates. We want the default rate to be
"display each new pattern as fast as possible". This is currently
achieved by the current loop (highly simplified!):
while generating patterns {
calculate next pattern
call window->Refresh()
call window->Update() (this should display results *immediately*)
call wxYield() to handle user events
}
The above code works perfectly fine with wxMSW and wxGTK, and with
wxMac 2.8, but with wxMac 3.0.1 many patterns are not seen due to
your guard code.
Now, I realize that this could be done differently (and better, to avoid
calling wxYield), but when I wrote the 1st version 9 years ago I was
new to wxWidgets and followed the example code in the Life demo which
has this loop:
case ID_TOPSPEED:
{
m_running = true;
m_topspeed = true;
UpdateUI();
while (m_running && m_topspeed)
{
OnStep();
wxYield();
}
break;
}
BTW, the Life demo is currently broken (and probably has been for some time).
It doesn't update patterns at all when the Start button is selected.
The simplest fix is to replace
m_canvas->DrawChanged();
in LifeFrame::OnStep() with these calls:
m_canvas->Refresh(false);
m_canvas->Update();
Andrew
--
Please read http://www.wxwidgets.org/support/mlhowto.htm before posting.
To unsubscribe, send email to wx-users+***@googlegroups.com
or visit http://groups.google.com/group/wx-users