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 1/2] 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); From cd33b79ae70280933e81068b05e615434bfcb987 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Fri, 5 May 2023 23:00:01 +0200 Subject: [PATCH 2/2] Fix an issue where stray KEY_UP events could confuse the control mapper into setting empty events This had some not-so-good consequences, like inability to map anything in VR, and sometimes empty MultiMappings would result that we could end up asserting on before the previous commit. --- Common/VR/PPSSPPVR.cpp | 4 +++- UI/ControlMappingScreen.cpp | 9 +++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/Common/VR/PPSSPPVR.cpp b/Common/VR/PPSSPPVR.cpp index 21fd41ea1e..7daf981e26 100644 --- a/Common/VR/PPSSPPVR.cpp +++ b/Common/VR/PPSSPPVR.cpp @@ -254,6 +254,7 @@ void UpdateVRInput(bool haptics, float dp_xscale, float dp_yscale) { keyInput.deviceId = controllerIds[j]; //process the key action + if (m.pressed != pressed) { if (pressed && haptics) { INVR_Vibrate(100, j, 1000); @@ -446,7 +447,8 @@ void UpdateVRInput(bool haptics, float dp_xscale, float dp_yscale) { mousePressed = pressed; } - //mouse wheel emulation + // mouse wheel emulation + // TODO: Spams key-up events if nothing changed! for (int j = 0; j < 2; j++) { keyInput.deviceId = controllerIds[j]; float scroll = -IN_VRGetJoystickState(j).y; diff --git a/UI/ControlMappingScreen.cpp b/UI/ControlMappingScreen.cpp index cbc4628b43..bcacf3f4d6 100644 --- a/UI/ControlMappingScreen.cpp +++ b/UI/ControlMappingScreen.cpp @@ -360,6 +360,13 @@ bool KeyMappingNewKeyDialog::key(const KeyInput &key) { } } if (key.flags & KEY_UP) { + // If the key released wasn't part of the mapping, ignore it here. Some device can cause + // stray key-up events. + InputMapping upMapping(key.deviceId, key.keyCode); + if (!mapping_.mappings.contains(upMapping)) { + return true; + } + if (callback_) callback_(mapping_); TriggerFinish(DR_YES); @@ -391,7 +398,9 @@ bool KeyMappingNewMouseKeyDialog::key(const KeyInput &key) { } mapped_ = true; + MultiInputMapping kdf(InputMapping(key.deviceId, key.keyCode)); + TriggerFinish(DR_YES); g_Config.bMapMouse = false; if (callback_)