lenmus / lomse

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

Crash in MusicXML score #388

Closed thebnich closed 1 year ago

thebnich commented 1 year ago

Hi, I'm hitting a crash in this score. Simply rendering a presenter created from this score should repro:

diff --git a/examples/tutorials/tutorial-1-x11/tutorial-1-x11.cpp b/examples/tutorials/tutorial-1-x11/tutorial-1-x11.cpp
index 69b24b1a..ee1f934f 100644
--- a/examples/tutorials/tutorial-1-x11/tutorial-1-x11.cpp
+++ b/examples/tutorials/tutorial-1-x11/tutorial-1-x11.cpp
@@ -130,15 +130,7 @@ void open_document()
     //and relationships between the document, its views and the interactors
     //to interact with the view
     delete m_pPresenter;
-    m_pPresenter = m_lomse.new_document(k_view_vertical_book,
-        "(lenmusdoc (vers 0.0)"
-            "(content "
-                "(para (txt \"Hello world!\"))"
-                "(score (vers 1.6) "
-                    "(instrument (musicData (clef G)(key C)(time 2 4)(n c4 q) )))"
-            ")"
-        ")",
-        Document::k_format_ldp);
+    m_pPresenter = m_lomse.open_document(k_view_vertical_book, "score.xml");

     //get the pointer to the interactor and register for receiving desired events
     if (SpInteractor spInteractor = m_pPresenter->get_interactor(0).lock())

I was able to reduce it to a (somewhat) minimal test case, but haven't had time yet to investigate beyond that, so I don't know what exactly is triggering this in the score.

cecilios commented 1 year ago

Thanks for reporting. Bug confirmed. Unfortunately, I'm going on a trip after lunch and I'll be away for three weeks so it will be impossible for me to debug and fix this until end of February. Sorry!

dmitrio95 commented 1 year ago

Actually maybe I can help with this, as I seem to have this issue fixed in my project. I have not submitted those patches before as I probably intended to rework some of them better before submitting, but they work for their purpose, so I have just opened a pull request (#389) with those patches at their current state.

The source of this issue seems to be a beam going across a bar line: изображение

When it plainly goes like this it shouldn't cause any issues, but with the default page size this bar line appears to be at the end of its system, so the beam eventually becomes cross-system. Lomse currently doesn't handle cross-system beams well, and that makes the application crash.

My solution to this was to add support for breaking beams across systems. Not sure if this is always what the user may expect, but it works and fixes the crash.

thebnich commented 1 year ago

Well that's convenient—thanks for sharing your fix!

cecilios commented 1 year ago

@dmitrio95 Thank you very much Dmitri. Long time without news. Hope everything goes well for you by there. I returned from my trip yesterday and will now start with this issue and to review your PR.