From bdb120ec9ee0afc6ca309d302b4b735374d88ee8 Mon Sep 17 00:00:00 2001 From: Joachim Schmitz Date: Thu, 23 Oct 2025 17:38:47 +0200 Subject: [PATCH] Fix crash when loading a certain MusicXML file Resolves: #30693 --- src/engraving/rendering/score/tlayout.cpp | 5 ++++- .../internal/musicxml/import/importmusicxmlpass2.cpp | 4 ++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/engraving/rendering/score/tlayout.cpp b/src/engraving/rendering/score/tlayout.cpp index 27835b2421aa3..9e82e9593e808 100644 --- a/src/engraving/rendering/score/tlayout.cpp +++ b/src/engraving/rendering/score/tlayout.cpp @@ -2191,7 +2191,7 @@ void TLayout::layoutFermata(const Fermata* item, Fermata::LayoutData* ldata) double x = 0.0; double y = item->placeAbove() ? 0.0 : item->staff()->staffHeight(item->tick()); const Segment* s = item->segment(); - const EngravingItem* e = s->element(item->track()); + const EngravingItem* e = s ? s->element(item->track()) : nullptr; if (e) { LD_CONDITION(e->ldata()->isSetBbox()); // e->shape() @@ -2227,6 +2227,9 @@ void TLayout::layoutFermata(const Fermata* item, Fermata::LayoutData* ldata) if (item->isStyled(Pid::OFFSET)) { y += item->offset().y(); } + if (!item->segment()) { + return; + } Shape staffShape = item->segment()->staffShape(item->staffIdx()); staffShape.removeTypes({ ElementType::FERMATA }); if (item->placeAbove()) { diff --git a/src/importexport/musicxml/internal/musicxml/import/importmusicxmlpass2.cpp b/src/importexport/musicxml/internal/musicxml/import/importmusicxmlpass2.cpp index 9c3ca272b04f7..28859909b7d32 100644 --- a/src/importexport/musicxml/internal/musicxml/import/importmusicxmlpass2.cpp +++ b/src/importexport/musicxml/internal/musicxml/import/importmusicxmlpass2.cpp @@ -5178,7 +5178,7 @@ void MusicXmlParserDirection::dashes(const String& type, const int number, { const MusicXmlExtendedSpannerDesc& spdesc = m_pass2.getSpanner({ ElementType::HAIRPIN, number }); if (type == u"start") { - TextLineBase* b = spdesc.isStopped ? toTextLine(spdesc.sp) : Factory::createTextLine(m_score->dummy()); + TextLineBase* b = spdesc.isStopped && spdesc.sp->isTextLine() ? toTextLine(spdesc.sp) : Factory::createTextLine(m_score->dummy()); // if (placement.empty()) placement = "above"; // TODO ? set default // hack: combine with a previous words element @@ -5202,7 +5202,7 @@ void MusicXmlParserDirection::dashes(const String& type, const int number, // use MusicXML specific type instead starts.push_back(MusicXmlSpannerDesc(b, ElementType::TEXTLINE, number)); } else if (type == u"stop") { - TextLine* b = spdesc.isStarted ? toTextLine(spdesc.sp) : Factory::createTextLine(m_score->dummy()); + TextLine* b = spdesc.isStarted && spdesc.sp->isTextLine() ? toTextLine(spdesc.sp) : Factory::createTextLine(m_score->dummy()); stops.push_back(MusicXmlSpannerDesc(b, ElementType::TEXTLINE, number)); } m_e.skipCurrentElement();