From 5dd72acc027728d0c70f8358f8f4abdfd71fa04a Mon Sep 17 00:00:00 2001 From: Paul Licameli Date: Sat, 4 Nov 2017 13:33:11 -0400 Subject: [PATCH] Bug1770: fix crash applying chains --- src/Track.cpp | 5 ++--- src/Track.h | 14 +++++++++++++- src/TrackPanel.cpp | 4 ++-- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/src/Track.cpp b/src/Track.cpp index e30563164..fad10ed10 100644 --- a/src/Track.cpp +++ b/src/Track.cpp @@ -882,9 +882,8 @@ void TrackList::DeletionEvent() void TrackList::ResizingEvent(TrackNodePointer node) { - auto e = std::make_unique(EVT_TRACKLIST_RESIZING); - if (!isNull(node)) - e->SetClientData(node->get()); + auto e = std::make_unique(EVT_TRACKLIST_RESIZING); + e->mpTrack = *node; // wxWidgets will own the event object QueueEvent(e.release()); } diff --git a/src/Track.h b/src/Track.h index f8459db35..7cbe04d0b 100644 --- a/src/Track.h +++ b/src/Track.h @@ -518,11 +518,23 @@ class AUDACITY_DLL_API SyncLockedTracksIterator final : public TrackListIterator * Clear, and Contains, plus serialization of the list of tracks. */ +struct TrackListEvent : public wxCommandEvent +{ + TrackListEvent(wxEventType commandType = wxEVT_NULL, int winid = 0) + : wxCommandEvent{ commandType, winid } {} + + TrackListEvent( const TrackListEvent& ) = default; + + wxEvent *Clone() const override { return new TrackListEvent(*this); } + + std::weak_ptr mpTrack; +}; + // Posted when tracks are reordered but otherwise unchanged. DECLARE_EXPORTED_EVENT_TYPE(AUDACITY_DLL_API, EVT_TRACKLIST_PERMUTED, -1); // Posted when some track was added or changed its height. -// The wxCommandEvent::GetClientData() method can be used to retrieve it. +// Cast to TrackListEvent and examine mpTrack to retrieve it. DECLARE_EXPORTED_EVENT_TYPE(AUDACITY_DLL_API, EVT_TRACKLIST_RESIZING, -1); // Posted when a track has been deleted from a tracklist. diff --git a/src/TrackPanel.cpp b/src/TrackPanel.cpp index 1916897d0..680a07c46 100644 --- a/src/TrackPanel.cpp +++ b/src/TrackPanel.cpp @@ -1158,10 +1158,10 @@ void TrackPanel::OnPlayback(wxCommandEvent &e) // ruler size for the track that triggered the event. void TrackPanel::OnTrackListResizing(wxCommandEvent & e) { - Track *t = (Track *) e.GetClientData(); + auto t = static_cast(e).mpTrack.lock(); // A deleted track can trigger the event. In which case do nothing here. if( t ) - UpdateVRuler(t); + UpdateVRuler(t.get()); e.Skip(); }