From be122a5a7315703b9cb54be1256cc6f990e97c7d Mon Sep 17 00:00:00 2001 From: Alexander Bock Date: Mon, 6 Feb 2023 23:17:16 +0100 Subject: [PATCH] No longer trigger an assert when binding a key to an action that does not exist (closes #2485) --- modules/server/src/topics/shortcuttopic.cpp | 8 ++++++++ src/interaction/keybindingmanager.cpp | 10 +++++----- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/modules/server/src/topics/shortcuttopic.cpp b/modules/server/src/topics/shortcuttopic.cpp index e6dd498704..db2eab047a 100644 --- a/modules/server/src/topics/shortcuttopic.cpp +++ b/modules/server/src/topics/shortcuttopic.cpp @@ -28,6 +28,7 @@ #include #include #include +#include using nlohmann::json; @@ -69,6 +70,13 @@ std::vector ShortcutTopic::shortcutsJson() const { global::keybindingManager->keyBindings(); for (const std::pair& keyBinding : keyBindings) { + if (!global::actionManager->hasAction(keyBinding.second)) { + // We don't warn here as we don't know if the user didn't expect the action + // to be there or not. They might have defined a keybind to do multiple things + // only one of which is actually defined + continue; + } + const KeyWithModifier& k = keyBinding.first; // @TODO (abock, 2021-08-05) Probably this should be rewritten to better account // for the new action mechanism diff --git a/src/interaction/keybindingmanager.cpp b/src/interaction/keybindingmanager.cpp index 8e7dcb1e83..585835f63f 100644 --- a/src/interaction/keybindingmanager.cpp +++ b/src/interaction/keybindingmanager.cpp @@ -55,11 +55,11 @@ void KeybindingManager::keyboardCallback(Key key, KeyModifier modifier, KeyActio auto ret = _keyLua.equal_range({ key, modifier }); for (auto it = ret.first; it != ret.second; ++it) { ghoul_assert(!it->second.empty(), "Action must not be empty"); - ghoul_assert( - global::actionManager->hasAction(it->second), - "Action must be registered" - ); - global::actionManager->triggerAction(it->second, ghoul::Dictionary()); + if (!global::actionManager->hasAction(it->second)) { + // Silently ignoring the unknown action as the user might have intended to + // bind a key to multiple actions, only one of which could be defined + global::actionManager->triggerAction(it->second, ghoul::Dictionary()); + } } } }