Volta attached to non-top staff deleted when correspond staff is removed

• Aug 27, 2013 - 15:09
S4 - Minor

1. Open this score.
2. 'Instruments...'
3. Click on bottom stave.
4. 'Remove'.
5. 'OK'.

Result: Crash.

Note: See attached log.

Using MuseScore 2.0 Nightly Build (025f37c) - Mac 10.7.5.

(Thanks to Chistabo .)

Attachment Size
Removing stave causes crash (Log).txt 61.51 KB


Title Removing stave causes crash Removing stave in presence of voltas causes crash

The crash is tightly related to the presence of voltas.
Indeed, if the voltas are deleted before removing the staff, everything works fine.

The same crash happens with the following steps:

  1. Create a new piano (2 staves) score.
  2. Drag and drop a volta from Line palette to one measure of the second staff. Even if the volta will be linked to the first staff, release the mouse when the cursor is over the second staff.
  3. Add -> Instruments... select the second (or the first) staff and remove.
  4. Ok to accept. -> crash

Note that if the volta is added to a measure of the first staff (i.e. the mouse is released when over the first staff) there is no crash and everything works as expected.

Attached the address sanitizer log for the original bug report. The staffIdx is 1 and score()->staff(staffIdx) at line 1001 of libmscore\system.cpp gives 0 (no staff at staffIdx):
if (all || (score()->staff(staffIdx)->show() && v) || (spanner->type() == Element::VOLTA))

Attachment Size
remove_staff_crash.txt 1.99 KB
Status (old) fixed active

Unfortunately, still active, but with slightly different steps:

  1. Open this file.
  2. Add -> Instruments...
  3. Click on TOP staff.
  4. Remove.
  5. Ok. -> crash

Moreover, if the bottom staff is removed, there is no crash, but one (actually two, because there are two overlapping voltae in the original file) volta disappear. This is due to 943c7e7b2

The crash is due to the fact that the volta attached to staff 1 is kept, while the volta attached to staff 0 is deleted, but staff 0 is deleted and the old staff 1 becomes staff 0, so the reference to staff 1 no more exists.
I still propose to automatically link every volta to the first staff of the first instrument: there will always be a first staff (staff at position 0), even if all the other staves are deleted (it is impossible to make a score empty of instruments).
I propose that voltae are not deleted like other spanners (so they are not lost when one staff is removed).

Edit: I was forgetting: Windows 8, commit 528d2976c2 (self-compiled)

I tried as well and I can't reproduce the crash.
However, there is still something which does not work as expected:

Openthis file: there is one 1. volta at measure 23 and two overlapping 2. voltae at measure 24.

Now, if you go to Add -> Instruments... and remove the TOP staff, one of the two 2. voltae disappears.
Otherwise, if you remove the BOTTOM staff, the 1. volta and one of the 2. voltae disappear.
In principle, information is disappearing (that's why I am not lowering the priority for now). In particular, in the second scenario, the missing 1. volta means a wrong score for the performer reading the score.

The pull request I proposed for this bug is no longer valid (the code has changed a lot), but I still think that we should attach voltae only to the first staff (and therefore put the voltae from an imported 1.3 files to the first staff, even if they were attached to other staves) and we should pay particular attention when staves are removed (in particular, if we decide to attach them to the first staff, we should avoid to delete them if the first staff is removed, but instead attach them to the new first staff).

Are you sure? Using the El Nuevo Dia score you originally uploaded? I can remove either staff with no crash. However, if I remove the top staff, certain items attached to the top staff are left orphaned and floating in the wrong place - like the initial tempo marking. And as ABL mentions, some of the volta disappear depending on which staff you remove.

Ok... so in 22ec44fe8a

  • I can't reproduce the initial bug report
  • #2 I can't reproduce.
  • #6 the crash is solved. The fact that volta are deleted is probably linked to this issue but different. The remark in #6 is the same than the remark in #9
  • #10 is the same than #6 and I can't reproduce (yes even on mac osx)
  • #11 The tempo thing is filed separately at #9845: [Trunk] Tempo Text not preserved after deleting bars, instruments or staves

So the crash is fixed. The remaining bug is about the Volta being deleted when the staff associated with it is removed. We could fix it as ABL proposed in his pull request by setting the volta track to 0 when we read it from the file. And by setting the track to 0 for all spanner anchored to Measure, currently only Voltas. Any other opinion?

I also cannot reproduce any of the above crashes, under Windows 8.1 or Linux Mint 13 (with address sanitizer enabled), commit 22ec44fe (self-compiled).
At the moment, the solution of setting all measure-anchored spanners on staff 0 will not completely prevent them from deletion, because after 943c7e7b2 deleting staff 0 deletes the associated spanners. We could set an exception for measure-anchored spanners so that they are not deleted an remain attached to staff 0 (which I think cannot be deleted in version 2.0, at the moment).