fix #63231: crash shortening a spanner #2094
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
See also https://musescore.org/en/node/66396. In both cases, there was a crash on an operation that normally invovles spanners being shortened in checkSpanner(), although the crash was OS-dependent. @AntonioBL tracked it down in that case to the undoChangeProperty() call, and I am 99% sure this will also explain https://musescore.org/en/node/63231.
My fix is to simply the shortening of the spanner outside the loop just as is done when removing them. I also restructured things a little to avoid calling computeEndElement() for spanners we are about to delete or shorten.
I also changed the call to undoChangeProperty() to undo(new ChangeProperty()). The main difference is that the former goes through links to make the same adjustment, but I don't think that is necessary or advisable here. For linked parts, we are going to call checkSpanner() on the linked parts separately. And for linked staves within the same score, we are going to add both spanners to this list separately, so I don't see any reason not to just shorten them separately too.
In the case of https://musescore.org/en/node/66396, it is still not known how this situation arose in the first place. This was not a case of shortening a score; it happened on read. Apparently there is a stray haipin in some of the mmrests in the parts for that score, and that probably suggests another bug somewhere that led to those being created. But we don't (yet) have steps to reproduce. My fix here simply allows those hairpins - which are not linked - to extend to the end of the relevant parts.