From ee46155d828e71aa02cbe7f689619288cb78b9a8 Mon Sep 17 00:00:00 2001 From: David Bailes Date: Sat, 27 Jul 2019 13:16:15 +0100 Subject: [PATCH] Bug 2176 - Crash when attempting to time shift multiple tracks Steps to reproduce: 1. create a new project in Audacity 2. add several tracks. 3. turn on Sync-Lock (Tracks, Sync-Lock Tracks checked) 4. Click on the Time Shift Tool. 5. Attempt to move tracks to the right (for example), clicking in the bottom track 6. It crashes. In the function: void TimeShiftHandle::CreateListOfCapturedClips(), the problem was the first occurrence of the line: auto &trackClip = state.capturedClipArray[i]; The subsequent call to AddClipsToCaptured(), can reallocate the array and so invalidate the reference. Fix: Don't use a reference. (TrackClip is not a large object.) --- src/tracks/ui/TimeShiftHandle.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/tracks/ui/TimeShiftHandle.cpp b/src/tracks/ui/TimeShiftHandle.cpp index 37356fa43..dba748743 100644 --- a/src/tracks/ui/TimeShiftHandle.cpp +++ b/src/tracks/ui/TimeShiftHandle.cpp @@ -269,8 +269,8 @@ void TimeShiftHandle::CreateListOfCapturedClips // because AddClipsToCaptured doesn't add duplicate clips); to remove // this behavior just store the array size beforehand. for (unsigned int i = 0; i < state.capturedClipArray.size(); ++i) { - { - auto &trackClip = state.capturedClipArray[i]; + auto trackClip = state.capturedClipArray[i]; + { // Capture based on tracks that have clips -- that means we // don't capture based on links to label tracks for now (until // we can treat individual labels as clips) @@ -284,8 +284,6 @@ void TimeShiftHandle::CreateListOfCapturedClips } #ifdef USE_MIDI { - // Beware relocation of array contents! Bind trackClip again. - auto &trackClip = state.capturedClipArray[i]; // Capture additional clips from NoteTracks trackClip.track->TypeSwitch( [&](NoteTrack *nt) { // Iterate over sync-lock group tracks.