From 57ff92b20c01ce6da39475858775619a532e106b Mon Sep 17 00:00:00 2001 From: James Crook Date: Thu, 9 Jan 2020 15:56:00 +0000 Subject: [PATCH] Bug 2275 - Crash when unchecking Multi-view with neither of the views checked --- .../wavetrack/ui/WaveTrackView.cpp | 39 ++++++++++++++----- 1 file changed, 29 insertions(+), 10 deletions(-) diff --git a/src/tracks/playabletrack/wavetrack/ui/WaveTrackView.cpp b/src/tracks/playabletrack/wavetrack/ui/WaveTrackView.cpp index 5491f10ee..10f1f29b8 100644 --- a/src/tracks/playabletrack/wavetrack/ui/WaveTrackView.cpp +++ b/src/tracks/playabletrack/wavetrack/ui/WaveTrackView.cpp @@ -559,31 +559,50 @@ void WaveTrackView::ToggleSubView(WaveTrackDisplay display) return false; } ) ) { auto &foundPlacement = mPlacements[found]; + auto index = foundPlacement.index; + unsigned nn = 0; + + // if found and active, deactivate it.. if ( foundPlacement.fraction > 0.0 ) { - auto index = foundPlacement.index; - foundPlacement = { -1, 0.0 }; - if (index >= 0) { - for ( auto &placement : mPlacements ) { - if ( placement.index > index ) - --placement.index; + for (auto &placement : mPlacements) { + if (placement.fraction > 0.0 && placement.index >= 0) { + nn++; + } + } + // if removing the last one, then don't! + // Switch to radio-button view instead. + if (nn <= 1) { + DoSetDisplay(display, 1.0); + SetMultiView(false); + } + else + { + foundPlacement = { -1, 0.0 }; + if (index >= 0) { + for (auto &placement : mPlacements) { + if (placement.index > index) + --placement.index; + } } } } + // else found and zero size, so add it on the bottom. else { float total = 0; int greatest = -1; - unsigned nn = 0; - int removedIndex = foundPlacement.index; for ( auto &placement : mPlacements ) { if ( placement.fraction >= 0.0 && placement.index >= 0 ) { // renumber in case there's an item removed. - if( (removedIndex >= 0) && (placement.index >= removedIndex)) - placement.index -= 1; + if( (index >= 0) && (placement.index >= index)) + --placement.index; total += placement.fraction; greatest = std::max( greatest, placement.index ); ++nn; } } + // + if ( index >= 0) + --nn; // Turn on the sub-view, putting it lowest, and with average of the // heights of the other sub-views foundPlacement = { greatest + 1, total / nn };