From 954aed8132dfe71b188634aaf700472b99629f74 Mon Sep 17 00:00:00 2001 From: Niek van den Berg Date: Mon, 8 Jun 2020 17:05:59 +0200 Subject: [PATCH] Fix #302573 - Crash undoing add instruments Root cause was in needViewportMove() which used the begin and end staff from the cmdState but the state wasn't adapted for the removed staff yet. --- mscore/scoreview.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/mscore/scoreview.cpp b/mscore/scoreview.cpp index de394b5cd32e4..94ad471aeaa8e 100644 --- a/mscore/scoreview.cpp +++ b/mscore/scoreview.cpp @@ -5276,8 +5276,9 @@ static bool needViewportMove(Score* cs, ScoreView* cv) mEnd = mEnd ? mEnd->nextMeasureMM() : nullptr; const bool isExcerpt = !cs->isMaster(); - const int startStaff = (isExcerpt || state.startStaff() < 0) ? 0 : state.startStaff(); - const int endStaff = (isExcerpt || state.endStaff() < 0) ? (cs->nstaves() - 1) : state.endStaff(); + const bool csStaves = (isExcerpt || (state.endStaff() < 0) || (state.endStaff() >= cs->nstaves())); + const int startStaff = csStaves ? 0 : state.startStaff(); + const int endStaff = csStaves ? (cs->nstaves() - 1) : state.endStaff(); for (Measure* m = mStart; m && m != mEnd; m = m->nextMeasureMM()) { for (int st = startStaff; st <= endStaff; ++st) {