From 104e8b50ba11fa110a8c8452c8e2518579ce35b9 Mon Sep 17 00:00:00 2001 From: James Crook <james.k.crook@gmail.com> Date: Fri, 8 Jan 2016 18:45:01 +0000 Subject: [PATCH] Bug 1296 - Zooming to maximum in longer multi-clip tracks crashes in all clips except the last Caused by a premature conversion of a wxInt64 to (int) so that a large positive number became negative. We now do the conversion after minning it against an integer width. --- src/TrackArtist.cpp | 45 +++++++++++++++++++-------------------------- 1 file changed, 19 insertions(+), 26 deletions(-) diff --git a/src/TrackArtist.cpp b/src/TrackArtist.cpp index 51cb4c7c0d..77b98f8afc 100644 --- a/src/TrackArtist.cpp +++ b/src/TrackArtist.cpp @@ -1585,29 +1585,26 @@ struct ClipParameters hiddenMid = rect; // If the left edge of the track is to the right of the left - // edge of the display, then there's some blank area to the + // edge of the display, then there's some unused area to the // left of the track. Reduce the "hiddenMid" hiddenLeftOffset = 0; if (tpre < 0) { - hiddenLeftOffset = std::min(rect.width, int( - zoomInfo.TimeToPosition(tOffset, 0 - , true - ) - )); + // Fix Bug #1296 caused by premature conversion to (int). + wxInt64 time64 = zoomInfo.TimeToPosition(tOffset, 0 , false); + hiddenLeftOffset = (time64 < rect.width) ? (int)time64 : rect.width; + hiddenMid.x += hiddenLeftOffset; hiddenMid.width -= hiddenLeftOffset; } // If the right edge of the track is to the left of the the right - // edge of the display, then there's some blank area to the right + // edge of the display, then there's some unused area to the right // of the track. Reduce the "hiddenMid" rect by the // size of the blank area. if (tpost > t1) { - const int hiddenRightOffset = std::min(rect.width, int( - zoomInfo.TimeToPosition(tOffset + t1, 0 - , true - ) - )); + wxInt64 time64 = zoomInfo.TimeToPosition(tOffset+t1, 0 , false); + const int hiddenRightOffset = (time64 < rect.width) ? (int)time64 : rect.width; + hiddenMid.width = std::max(0, hiddenRightOffset - hiddenLeftOffset); } @@ -1617,29 +1614,25 @@ struct ClipParameters mid = rect; // If the left edge of the track is to the right of the left - // edge of the display, then there's some blank area to the - // left of the track. Reduce the "hiddenMid" + // edge of the display, then there's some unused area to the + // left of the track. Reduce the "mid" leftOffset = 0; if (tpre < 0) { - leftOffset = std::min(rect.width, int( - zoomInfo.TimeToPosition(tOffset, 0 - , false - ) - )); + wxInt64 time64 = zoomInfo.TimeToPosition(tOffset, 0 , false); + leftOffset = (time64 < rect.width) ? (int)time64 : rect.width; + mid.x += leftOffset; mid.width -= leftOffset; } // If the right edge of the track is to the left of the the right - // edge of the display, then there's some blank area to the right - // of the track. Reduce the "hiddenMid" rect by the + // edge of the display, then there's some unused area to the right + // of the track. Reduce the "mid" rect by the // size of the blank area. if (tpost > t1) { - const int distortedRightOffset = std::min(rect.width, int( - zoomInfo.TimeToPosition(tOffset + t1, 0 - , false - ) - )); + wxInt64 time64 = zoomInfo.TimeToPosition(tOffset+t1, 0 , false); + const int distortedRightOffset = (time64 < rect.width) ? (int)time64 : rect.width; + mid.width = std::max(0, distortedRightOffset - leftOffset); } } -- GitLab