Fix crash on transpose of specific 3.6 score #16770
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.
Resolves: #15727
The problem arises because, in this specific file (see related issue), the Clarinet 1 part has gone out of sync with the score, and there is an orphaned KeySig event which, for some reason, exists in the Clarinet 1 part, but not in the score.
How or why exactly that happened, I really can't tell. I've tried everything I could think of to recreate the same issue in Musescore 4, but I couldn't (and by looking at the code, it really seems not possible to do so with the score-part model we have in Musescore 4). So I'm inclined to think that this is entirely a 3.6 problem (the file was originally created in 3.6 and the crash indeed also happens in 3.6, so it isn't about anything new that we have introduced).
In terms of avoiding the crash, it is simply a matter of null-checking the segment before using it (which I think is worth doing anyway for safety, given that's it's obtained from a function that may return null).