diff --git a/src/Track.cpp b/src/Track.cpp index aca0103ed..44a86d058 100644 --- a/src/Track.cpp +++ b/src/Track.cpp @@ -1183,7 +1183,7 @@ bool TrackList::ApplyPendingTracks() return result; } -std::shared_ptr Track::SubstitutePendingChangedTrack() const +std::shared_ptr Track::SubstitutePendingChangedTrack() { // Linear search. Tracks in a project are usually very few. auto pList = mList.lock(); @@ -1199,6 +1199,11 @@ std::shared_ptr Track::SubstitutePendingChangedTrack() const return SharedPointer(); } +std::shared_ptr Track::SubstitutePendingChangedTrack() const +{ + return const_cast(this)->SubstitutePendingChangedTrack(); +} + std::shared_ptr Track::SubstituteOriginalTrack() const { auto pList = mList.lock(); diff --git a/src/Track.h b/src/Track.h index 5a1757a2d..748e7f596 100644 --- a/src/Track.h +++ b/src/Track.h @@ -252,6 +252,7 @@ class AUDACITY_DLL_API Track /* not final */ // Find anything registered with TrackList::RegisterPendingChangedTrack and // not yet cleared or applied; if no such exists, return this track + std::shared_ptr SubstitutePendingChangedTrack(); std::shared_ptr SubstitutePendingChangedTrack() const; // If this track is a pending changed track, return the corresponding diff --git a/src/tracks/ui/TrackButtonHandles.cpp b/src/tracks/ui/TrackButtonHandles.cpp index f14492cc5..9947f8b7e 100644 --- a/src/tracks/ui/TrackButtonHandles.cpp +++ b/src/tracks/ui/TrackButtonHandles.cpp @@ -154,10 +154,11 @@ UIHandle::Result CloseButtonHandle::CommitChanges auto pTrack = mpTrack.lock(); if (pTrack) { + auto toRemove = pTrack->SubstitutePendingChangedTrack(); TransportActions::StopIfPaused( *pProject ); if (!ProjectAudioIO::Get( *pProject ).IsAudioActive()) { // This pushes an undo item: - TrackUtilities::DoRemoveTrack(*pProject, pTrack.get()); + TrackUtilities::DoRemoveTrack(*pProject, toRemove.get()); // Redraw all tracks when any one of them closes // (Could we invent a return code that draws only those at or below // the affected track?)