Layout shift in measure at start of system

• May 30, 2019 - 07:03
Reported version
3.1
Priority
P0 - Critical
Type
Functional
Frequency
Once
Severity
S3 - Major
Reproducibility
Always
Status
closed
Regression
No
Workaround
No
Project

Reported in https://musescore.org/en/node/289919, I have attached a simplified example.

1) load attached score
2) select first note
3) hit Down arrow to change pitch
4) observe the first measure of the next system

Before:

layout-shift-before.png

After:

layout-shift-after.png

So far I can say the triggers include having multiple staves with key signatures of different widths - so, different transposition, or pitched and unpitched. The issue also goes away if I delete the title frame or page break on it, which is to say it seems to not occur on page 1.

There are similarities between this and #289892: Bad layout of mmrest at start of system in that it has to do with setting the width of the first measure of a system after a range layout. In this case, we're setting the correct width for the measure when we first decide the system does not need a full layout, but it seems it gets stretched later anyhow, not sure why yet. Also, it's clear the notes are overlapping the key signature segment which shouldn't happen, leading me to think the problem has to do with setting the segment shape or min distance, both things I was messing with recently.

Attachment Size
layout-shift-2.mscz 2.13 KB

Comments

Title Layout shift in measure at start of system with Layout shift in measure at start of system

So far I can also say the page structure is relevant, I can't make a problem occur on the first page but can on subsequent pages. This appears to be because we start collecting the systems on the subsequent pages while still processing the first page, then realize too late the system wasn't going to fit on this page anyhow and roll back (the "rangeWasDone" code in collectPage). I'm currently thinking this code was never really working right (and there are comments in there from others expressing confusion as well), but that the problems only became exposed with my changes for https://github.com/musescore/MuseScore/pull/4866.

Further analysis: even though in theory we're done once we first encounter the measure that eventually gets messed up - the range is completed - we actually lay out that system again specifically because of the rollback of rangeDone. That rollback code was added just before release of 3.0, in https://github.com/musescore/MuseScore/pull/4373. I think I get why that added, but maybe this went too far, it shouldn't have forced more systems to be collected, just made sure we keep calculating system positions. And in fact, a fix I made recently for other system spacing issue might have made that rollback irrelevant. At least, I can't reproduce the original problem from #279367: First system on a page may not fit to the page even if I remove the rollback, and I suspect it's because my changes in https://github.com/musescore/MuseScore/pull/5051

More testing is needed to verify there are no other dependencies here, and in any case, even if it wasn't strictly necessary to lay out the system containing the messed up measure, it also shouldn't have hurt anything. Somehow we're getting the width of the measure wrong on this relayout, presumably having something to do with all that adding and removing of the header that goes on while adding measures to the system and somehow the key signature segment getting the wrong width in the process. So I'd like to understand that as well, and then hopefully submit a PR with both fixes.

I've figured out why the key signature width changes from the first layout to the second. It's because of the measure rest on the staff with the wider key signature. The first we layout, it hasn't been centered yet, and we calculate a minimum distance from the key signature to that rest, which ensures that all notes and rests on all staves start after the widest key signature. But by the next layout of the measure, the rest has been centered, so we no longer think we need to allocate space to clear the key signature for that staff.

So, the full set of conditions for the bug to appear:

1) multiple staves with different key signatures
2) >1 page (issue will only show after first page)
3) full measure rest on the first measure of a system, for staff with one of the widest key signatures

I do want to revert the rangeDone rollback so we don't layout the system in question unnecessarily to begin with. But since I can't guarantee there will never be multiple layouts of the same system, I plan to deal with the full measure rest (will check repeat measure too).

Fix version
3.2.0