lenmus / lomse

A C++ library for rendering, editing and playing back music scores.
MIT License
120 stars 28 forks source link

Fix a crash on fixing a chord-rest collision due to a missing pointer to the chord's base note #331

Closed dmitrio95 closed 3 years ago

dmitrio95 commented 3 years ago

This PR fixes a crash which happens on engraving this test score: noterest-collision-fixer-crash.musicxml.txt

The crash happens at this line because the collision fixer tries to access the pointer to the chord's base note which is null in this case. This happens because this pointer is set only for some notes in a chord (which are marked as "start", "link" or "flag" notes) and for some notes this pointer may be left unassigned. The proposed fix is to explicitly set the pointer to the base note for all notes in a chord so that the collision fixer or any other parts of the engraving algorithm can always access the base note by that pointer.

To avoid duplication I have also removed set_base_note_shape() calls when setting start, link and flag notes for a base note but this is not a necessary part of this patch.

cecilios commented 3 years ago

Thank you. I will review this as soon as possible. Perhaps you already have deduced the purpose of identifying and marking "start", "link" and "flag" notes. If not, I attach some information about the chord shape.

Lomse_Hacking_Guide--Graphic_model--Chords.pdf

cecilios commented 3 years ago

The changes look correct to me and all test passed.

I agree with the changes. Before adding the 'collision fixer' the pointer was not needed in other notes. But clearly, it is better to explicitly set the pointer to the base note for all notes in a chord to avoid future problems with new code.

Merging! Thank you very much for the PR.