Crash after deletion of a linked staff in a score with parts

• Jan 20, 2016 - 21:10
Type
Functional
Severity
S2 - Critical
Status
closed
Project
Tags

cc3b529 / Windows7

1) Guitar + Tablature template

2) Generate parts

3) Delete the tab staff (or first standard staff)

4) Enter a note in the remaining staff

Result: crash

- For more explanation, see: https://musescore.org/fr/node/94711#comment-418846


Comments

We have 4 linked staves after step 2):
1- the standard staff in the main score
2- the tab staff in the main score
3- the standard staff in the part
4- the tab staff in the part
The problem is that the _linkedStaves list of the residual staves (i.e. those which remain after the deletion) is not properly updated during the staff removal. I tried a possible initial solution here , where the linked staff in the part is removed only if it corresponds also in the order of relative staves inside the instrument (for example if we delete the tab staff in the main score, only the tab staff in the part is deleted, while the standard staves in main score and part are left), and where all removed staves are removed from the linkedStaves list (note that this list is shared among all the linked staves).
However, I am not sure about the unlinking step with respect to s2 in the added code, since we do not know a priori which staff this s2 will be (we only know that it is different from the one being removed by the user, but it could be one in a part, and in the unlink function, line 840 of libmscore/staff.cpp, at the end the linkedstaves is set to 0 for the removed staves, necessary for the undo/redo chain).
Moreover, I experience problems with the staves after the undo comand, i.e. they are not properly re-linked after undo.
I am a little stuck.
Any help, please?

There are quite a few other bugs that relate to the similar steps. Indeed, there is a problem with the list of linked staves, but I think it's deeper - each individual element on the remaining staff is still linked to the corresponding element in the now-deleted staff. See for example #89636: Crash on change duration (and other operations) after delete part and insert or delete measure and in particular my comment at https://musescore.org/en/node/89636#comment-395351.

I think that the problem could be the same: in #89636: Crash on change duration (and other operations) after delete part and insert or delete measure we are trying to access alinked note in the already-deleted part, as you correctly point out.
This stems from the fact that in undoChangeChordRestLen the list of linked staves is populated wrongly in undo.cpp, here: line 655 ; in particular, in #89636: Crash on change duration (and other operations) after delete part and insert or delete measure it contains 2 staves (instead of 1, or of being null) even if one of them was deleted. In this bug report it contains 3 staves, but 3 of the 4 initial staves were deleted (and one of them was wrongly deleted).
Therefore, I think that if we manage to fix the list of linked staves when we are deleting the staff, we should probably avoid these kind of bugs.

I tried to go on and here is where I am now:
//github.com/musescore/MuseScore/compare/musescore:db2244c...AntonioBL:4d4a11a
in the case of this bug report it mostly works. It now sometimes creates an empty measure (i.e. no full measure rest is created) when undoing while looking at a part the insertion of notes done in the main score, after some undo/redo steps of deletion of the 2nd or 1st staff (and note insertion and undo in the meantime). I couldn't find a simple reproducible case for now.

I didn't check if everything works fine for normal linked staves and/or normal staves in the part when they are deleted via the instruments dialog.

The bug of #89636: Crash on change duration (and other operations) after delete part and insert or delete measure is similar (i.e. linkedStaves is not updated), but it originates from another point in the code; in particular that part of the code calls Score::removeExcerpt, is the unlink of staves ever called in that case?

Status (old) patch (ready to commit) fixed

Fixed in branch master, commit 8bf08c2328

fix #89636 fix #94911 fix #70226 fix #91351: unlink the right staves when deleting a part, or deleting a linked staff. Do not store several times the same staves in linkedStaves

second take

Fixed in branch master, commit c6ccf18398

Merge pull request #2397 from lasconic/fix-89636-and-more

fix #89636 fix #94911 fix #70226 fix #91351: unlink the right staves when deleting a part, or deleting a linked staff. Do not store several times the same staves in linkedStaves

Fixed in branch 2.0.3, commit 7781e92a03

fix #89636 fix #94911 fix #70226 fix #91351: unlink the right staves when deleting a part, or deleting a linked staff. Do not store several times the same staves in linkedStaves

second take