From 90f66d04c3b0dbb04e64c13ce13d389f57f80160 Mon Sep 17 00:00:00 2001 From: Cubiking Date: Mon, 23 Mar 2026 19:14:37 +0000 Subject: [PATCH] Fix EditStaff dialog crash on startup The crash occurred because initStaff() was called in the constructor before the context injection system was fully initialized. After the MUSE_MULTICONTEXT_WIP removal, globalContext() returns null during construction, causing a segfault when notation() is called. Fixed by moving initStaff() from the constructor to showEvent(), ensuring the context is ready before accessing it. --- src/notationscene/widgets/editstaff.cpp | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/notationscene/widgets/editstaff.cpp b/src/notationscene/widgets/editstaff.cpp index f5db540a7bf02..aa9183d512d5f 100644 --- a/src/notationscene/widgets/editstaff.cpp +++ b/src/notationscene/widgets/editstaff.cpp @@ -64,8 +64,6 @@ EditStaff::EditStaff(QWidget* parent) setWindowFlags(this->windowFlags() & ~Qt::WindowContextHelpButtonHint); setModal(true); - initStaff(); - editStaffTypeDialog = new EditStaffType(this); editStaffTypeDialog->setWindowModality(Qt::WindowModal); @@ -166,6 +164,7 @@ void EditStaff::setStaff(Staff* s, const Fraction& tick) void EditStaff::showEvent(QShowEvent* event) { + initStaff(); WidgetStateStore::restoreGeometry(this); QDialog::showEvent(event); } @@ -443,6 +442,10 @@ INotationPartsPtr EditStaff::masterNotationParts() const void EditStaff::initStaff() { + if (!globalContext()) { + return; + } + const INotationPtr notation = this->notation(); const INotationInteractionPtr interaction = notation ? notation->interaction() : nullptr; auto context = interaction ? interaction->hitElementContext() : INotationInteraction::HitElementContext(); @@ -522,8 +525,10 @@ void EditStaff::applyPartProperties() String _lsn = longStaffName->toPlainText(); if (!mu::engraving::Text::validateText(_sn) || !mu::engraving::Text::validateText(_ln) || !mu::engraving::Text::validateText(_ssn) || !mu::engraving::Text::validateText(_lsn)) { - interactive()->warning(muse::trc("notation/staffpartproperties", "Invalid instrument name"), - muse::trc("notation/staffpartproperties", "The instrument name is invalid.")); + if (interactive()) { + interactive()->warning(muse::trc("notation/staffpartproperties", "Invalid instrument name"), + muse::trc("notation/staffpartproperties", "The instrument name is invalid.")); + } return; } QString sn = _sn; @@ -577,6 +582,10 @@ void EditStaff::applyPartProperties() void EditStaff::showReplaceInstrumentDialog() { + if (!selectInstrumentsScenario()) { + return; + } + async::Promise templ = selectInstrumentsScenario()->selectInstrument(m_instrumentKey); templ.onResolve(this, [this](const InstrumentTemplate& val) { const StaffType* staffType = val.staffTypePreset;