Crash undoing add instruments

• Mar 19, 2020 - 19:41
Reported version
3.x-dev
Priority
P0 - Critical
Type
Functional
Frequency
Once
Severity
S2 - Critical
Reproducibility
Always
Status
closed
Regression
Yes
Workaround
No
Project

Crash in current master with the following steps:

1) default score
2) edit / instruments, add something (flute, say)
3) undo

Result: assertion failure, looks to be trying to move viewport but using an invalid staff index


Comments

I could reproduce under Linux Mint 19.3, debug build of c458cc34eb with the given steps.
Here is the backtrace (only the relevant part:

-6 0x000055555c659436 in Ms::System::staff(int) const (this=0x6120006a8340, staffIdx=1)
at libmscore/system.h:132
-7 0x000055555f02116e in Ms::StaffLines::pagePos() const (this=0x611001608180)
at libmscore/stafflines.cpp:53
-8 0x000055555f021628 in Ms::StaffLines::canvasPos() const (this=0x611001608180)
at libmscore/stafflines.cpp:62
-9 0x000055555d6880d6 in Ms::needViewportMove(Ms::Score*, Ms::ScoreView*) (cs=0x62c000018200, cv=0x617000054b00)
at mscore/scoreview.cpp:5090
-10 0x000055555d688abe in Ms::ScoreView::moveViewportToLastEdit() (this=0x617000054b00)
at mscore/scoreview.cpp:5118
-11 0x000055555c523b51 in Ms::MuseScore::endCmd(bool) (this=0x61b000081880, undoRedo=true)
at mscore/musescore.cpp:6006
-12 0x000055555c50de57 in Ms::MuseScore::undoRedo(bool) (this=0x61b000081880, undo=true)
at mscore/musescore.cpp:4903

In particular, in needViewportMove funtion the startStaff and the endStaff are both 1 (retrieved from state const CmdState& state = cs->cmdState();), but in the score there is only staff 0 after the undo (staff 1 was "un-done").

Status PR created fixed

Fixed in branch 3.x, commit 954aed8132

_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._

Fix version
3.5.0