Score and System destructors conflict with each other
While experimenting with PR 4166 (do merge it in time, please), I’ve found that trying to delete
a MasterScore causes uninitialised memory access (visible in Valgrind, but occasionally causes later program crashes).
I’ve tracked this down to System::~System
and Score::~Score
both trying to access measures (MeasureBase
) which they both have in a list. The problem is, the one that runs first deletes them, while the second one still accesses them. They have different lists, of course…
This is new in 3.x — in 2.x, only one of them dealt with MeasureBase
s, hence no conflict.
I think the problem comes from the following:
A score has a number of MeasureBase
s, which are grouped into systems. However, the score also has a list of them, instead of always accessing them via the systems. The system destructor does not destroy the measures, merely sets their system reference to nullptr.
The fix is likely to be complicated and involve restructuring a lot. ☹
Comments
https://github.com/musescore/MuseScore/pull/4001 fixes this completely for me.
Fixed in branch master, commit e85f3a218c
fix #278969: delete systems before measures on score destruction
As layout-only objects systems need to correctly update the state of
the related measures and spanners on its destruction. For this
reason it may introduce freed memory writing if score is destroyed
in an incorrect order.
Fix confirmed.
Automatically closed -- issue fixed for 2 weeks with no activity.