Skip to content

Commit

Permalink
Check if MuseSampler module is added before creating MuseSounds menu …
Browse files Browse the repository at this point in the history
…items

If the MuseSampler module is not added, then its actions are also not added, so trying to call `makeMenuItem` for a MuseSounds action returns nullptr. And nullptrs in menu items lists cause crashes later on.
  • Loading branch information
cbjeukendrup committed Dec 9, 2024
1 parent 64b0bb4 commit 3be6705
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 30 deletions.
4 changes: 2 additions & 2 deletions src/app/appfactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,12 +235,12 @@ std::shared_ptr<muse::IApplication> AppFactory::newGuiApp(const CmdOptions& opti

#ifdef MUSE_MODULE_MUSESAMPLER
bool needAdd = true;
if (runtime::isDebug()) {
#ifndef MUSE_MODULE_MUSESAMPLER_ENABLE_DEBUG
if (runtime::isDebug()) {
needAdd = false;
LOGI() << "Muse Sampler is not a debuggable binary. Skipping adding.";
#endif
}
#endif

if (needAdd) {
app->addModule(new muse::musesampler::MuseSamplerModule());
Expand Down
17 changes: 10 additions & 7 deletions src/appshell/view/appmenumodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -426,15 +426,18 @@ MenuItem* AppMenuModel::makeDiagnosticsMenu()
};

#ifdef MUSE_MODULE_MUSESAMPLER
MenuItemList museSamplerItems {
makeMenuItem("musesampler-check"),
};
bool isMuseSamplerModuleAdded = museSamplerInfo() != nullptr;
if (isMuseSamplerModuleAdded) {
MenuItemList museSamplerItems {
makeMenuItem("musesampler-check"),
};

if (globalConfiguration()->devModeEnabled()) {
museSamplerItems << makeMenuItem("musesampler-reload");
}
if (globalConfiguration()->devModeEnabled()) {
museSamplerItems << makeMenuItem("musesampler-reload");
}

items << makeMenu(TranslatableString("appshell/menu/diagnostics", "&Muse Sampler"), museSamplerItems, "menu-musesampler");
items << makeMenu(TranslatableString("appshell/menu/diagnostics", "&Muse Sampler"), museSamplerItems, "menu-musesampler");
}
#endif

if (globalConfiguration()->devModeEnabled()) {
Expand Down
48 changes: 27 additions & 21 deletions src/appshell/view/appmenumodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,47 +19,55 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef MU_APPSHELL_APPMENUMODEL_H
#define MU_APPSHELL_APPMENUMODEL_H
#pragma once

#include "context/iglobalcontext.h"
#include "uicomponents/view/abstractmenumodel.h"

#include "muse_framework_config.h"

#include "modularity/ioc.h"
#include "actions/iactionsdispatcher.h"
#include "context/iglobalcontext.h"
#include "extensions/iextensionsprovider.h"
#include "global/iglobalconfiguration.h"
#ifdef MUSE_MODULE_MUSESAMPLER
#include "musesampler/imusesamplerinfo.h"
#endif
#include "project/iprojectconfiguration.h"
#include "project/irecentfilescontroller.h"
#include "ui/imainwindow.h"
#include "ui/iuiactionsregister.h"
#include "ui/inavigationcontroller.h"
#include "ui/iuiactionsregister.h"
#include "ui/iuiconfiguration.h"
#include "actions/iactionsdispatcher.h"
#include "update/iupdateconfiguration.h"
#include "workspace/iworkspacemanager.h"

#include "iappshellconfiguration.h"
#include "project/irecentfilescontroller.h"
#include "internal/iappmenumodelhook.h"
#include "extensions/iextensionsprovider.h"
#include "update/iupdateconfiguration.h"
#include "global/iglobalconfiguration.h"
#include "project/iprojectconfiguration.h"

namespace mu::appshell {
class AppMenuModel : public muse::uicomponents::AbstractMenuModel
{
Q_OBJECT

public:
muse::Inject<IAppMenuModelHook> appMenuModelHook = { this };
muse::Inject<IAppShellConfiguration> configuration = { this };
muse::Inject<mu::context::IGlobalContext> globalContext = { this };
muse::Inject<muse::IGlobalConfiguration> globalConfiguration = { this };
muse::Inject<muse::actions::IActionsDispatcher> actionsDispatcher = { this };
muse::Inject<muse::extensions::IExtensionsProvider> extensionsProvider = { this };
#ifdef MUSE_MODULE_MUSESAMPLER
muse::Inject<muse::musesampler::IMuseSamplerInfo> museSamplerInfo = { this };
#endif
muse::Inject<muse::ui::IMainWindow> mainWindow = { this };
muse::Inject<muse::ui::IUiActionsRegister> uiActionsRegister = { this };
muse::Inject<muse::ui::INavigationController> navigationController = { this };
muse::Inject<muse::ui::IUiActionsRegister> uiActionsRegister = { this };
muse::Inject<muse::ui::IUiConfiguration> uiConfiguration = { this };
muse::Inject<muse::actions::IActionsDispatcher> actionsDispatcher = { this };
muse::Inject<muse::workspace::IWorkspaceManager> workspacesManager = { this };
muse::Inject<IAppShellConfiguration> configuration = { this };
muse::Inject<project::IRecentFilesController> recentFilesController = { this };
muse::Inject<IAppMenuModelHook> appMenuModelHook = { this };
muse::Inject<muse::extensions::IExtensionsProvider> extensionsProvider = { this };
muse::Inject<muse::update::IUpdateConfiguration> updateConfiguration = { this };
muse::Inject<muse::IGlobalConfiguration> globalConfiguration = { this };
muse::Inject<muse::workspace::IWorkspaceManager> workspacesManager = { this };
muse::Inject<project::IProjectConfiguration> projectConfiguration = { this };
muse::Inject<mu::context::IGlobalContext> globalContext = { this };
muse::Inject<project::IRecentFilesController> recentFilesController = { this };

public:
explicit AppMenuModel(QObject* parent = nullptr);
Expand Down Expand Up @@ -105,5 +113,3 @@ class AppMenuModel : public muse::uicomponents::AbstractMenuModel
void updateUndoRedoItems();
};
}

#endif // MU_APPSHELL_APPMENUMODEL_H

0 comments on commit 3be6705

Please sign in to comment.