From 43291687a5a10e873e8be9971a8f7272c7b4927b Mon Sep 17 00:00:00 2001 From: Darrell Walisser Date: Sat, 25 Feb 2017 16:16:42 -0500 Subject: [PATCH] Bug 1401 - Wait for window visibility before starting timer --- src/TrackPanel.cpp | 21 ++++++++++++++++++++- src/TrackPanel.h | 1 + 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/TrackPanel.cpp b/src/TrackPanel.cpp index 623a98754..5a4b1da71 100644 --- a/src/TrackPanel.cpp +++ b/src/TrackPanel.cpp @@ -516,7 +516,8 @@ TrackPanel::TrackPanel(wxWindow * parent, wxWindowID id, mTimeCount = 0; mTimer.parent = this; - mTimer.Start(kTimerInterval, FALSE); + // Timer is started after the window is visible + GetProject()->Bind(wxEVT_IDLE, &TrackPanel::OnIdle, this); //Initialize a member variable pointing to the current //drawing track. @@ -904,6 +905,24 @@ AudacityProject * TrackPanel::GetProject() const return (AudacityProject*)pWind; } +void TrackPanel::OnIdle(wxIdleEvent& event) +{ + // The window must be ready when the timer fires (#1401) + if (IsShownOnScreen()) + { + mTimer.Start(kTimerInterval, FALSE); + + // Timer is started, we don't need the event anymore + GetProject()->Unbind(wxEVT_IDLE, &TrackPanel::OnIdle, this); + } + else + { + // Get another idle event, wx only guarantees we get one + // event after "some other normal events occur" + event.RequestMore(); + } +} + /// AS: This gets called on our wx timer events. void TrackPanel::OnTimer(wxTimerEvent& ) { diff --git a/src/TrackPanel.h b/src/TrackPanel.h index 6c09d0631..b8d719217 100644 --- a/src/TrackPanel.h +++ b/src/TrackPanel.h @@ -171,6 +171,7 @@ class AUDACITY_DLL_API TrackPanel final : public OverlayPanel { virtual double GetMostRecentXPos(); + virtual void OnIdle(wxIdleEvent & event); virtual void OnTimer(wxTimerEvent& event); virtual int GetLeftOffset() const { return GetLabelWidth() + 1;}