fix #290546: corruption on copy/paste end final mmrest #5191
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 https://musescore.org/en/node/290546
Problem is simple: when selecting to the end of a score that ends in an mmrest, we are setting "ls" to the last segment of the score, but that's not right - if there hadn't been an mmrest, ls would have been nullptr. That's the usual convention - the "last segment" pointer is supposed to be the segment after the selection, or to nullkptr, so that loops can stop before that specified segment. And that's where the corruption comes in - we're stopping before the last segment of the score, which in this case is the measure rest in the underlying piece (there's no barline in the underlying measure if it hasn't been laid out yet).
Anyhow, that's the fix - setting "ls" to nullptr rather than lastSegment(). Potentially this change could have been made in the selection code rather than here, but that would have greater impact on other things and risk regressions.