From eec1ad5a75710ec4d4ccf8330d16907ca8e6051c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Fri, 5 May 2023 22:26:27 +0200 Subject: [PATCH] Add some checks to try to prevent empty MultiInputMapping from arising, assert->log --- Core/KeyMap.cpp | 18 ++++++++++++++---- UI/ControlMappingScreen.cpp | 5 +++++ 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/Core/KeyMap.cpp b/Core/KeyMap.cpp index 6a52fbc4c4..9f4c482853 100644 --- a/Core/KeyMap.cpp +++ b/Core/KeyMap.cpp @@ -48,14 +48,17 @@ std::set g_seenPads; std::map g_padNames; std::set g_seenDeviceIds; -// Utility... +// Utility for UI navigation void SingleInputMappingFromPspButton(int btn, std::vector *mappings, bool ignoreMouse) { std::vector multiMappings; InputMappingsFromPspButton(btn, &multiMappings, ignoreMouse); mappings->clear(); for (auto &mapping : multiMappings) { - _dbg_assert_(!mapping.empty()); - mappings->push_back(mapping.mappings[0]); + if (!mapping.empty()) { + mappings->push_back(mapping.mappings[0]); + } else { + WARN_LOG(COMMON, "Encountered empty mapping in multi-mapping for button %d", btn); + } } } @@ -598,6 +601,11 @@ bool ReplaceSingleKeyMapping(int btn, int index, MultiInputMapping key) { return false; } } + + if (key.empty()) { + return false; + } + KeyMap::g_controllerMap[btn][index] = key; g_controllerMapGeneration++; @@ -702,8 +710,10 @@ void LoadFromIni(IniFile &file) { for (size_t j = 0; j < mappings.size(); j++) { MultiInputMapping input = MultiInputMapping::FromConfigString(mappings[j]); + if (input.empty()) { + continue; // eat empty mappings, however they arose, so they can't keep haunting us. + } SetInputMapping(psp_button_names[i].key, input, false); - for (auto mapping : input.mappings) { g_seenDeviceIds.insert(mapping.deviceId); } diff --git a/UI/ControlMappingScreen.cpp b/UI/ControlMappingScreen.cpp index 0e3283641d..cbc4628b43 100644 --- a/UI/ControlMappingScreen.cpp +++ b/UI/ControlMappingScreen.cpp @@ -163,6 +163,11 @@ void SingleControlMapper::Refresh() { } void SingleControlMapper::MappedCallback(MultiInputMapping kdf) { + if (kdf.empty()) { + // Don't want to try to add this. + return; + } + switch (action_) { case ADD: KeyMap::SetInputMapping(pspKey_, kdf, false);