No longer trigger an assert when binding a key to an action that does not exist (closes #2485)

This commit is contained in:
Alexander Bock
2023-02-06 23:17:16 +01:00
parent f7ff2e33da
commit be122a5a73
2 changed files with 13 additions and 5 deletions

View File

@@ -28,6 +28,7 @@
#include <openspace/engine/globals.h>
#include <openspace/interaction/actionmanager.h>
#include <openspace/interaction/keybindingmanager.h>
#include <ghoul/logging/logmanager.h>
using nlohmann::json;
@@ -69,6 +70,13 @@ std::vector<nlohmann::json> ShortcutTopic::shortcutsJson() const {
global::keybindingManager->keyBindings();
for (const std::pair<const KeyWithModifier, std::string>& 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

View File

@@ -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());
}
}
}
}