Skip to content

Commit

Permalink
Add some checks to try to prevent empty MultiInputMapping from arisin…
Browse files Browse the repository at this point in the history
…g, assert->log
  • Loading branch information
hrydgard committed May 5, 2023
1 parent 3318088 commit eec1ad5
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
18 changes: 14 additions & 4 deletions Core/KeyMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,17 @@ std::set<std::string> g_seenPads;
std::map<int, std::string> g_padNames;
std::set<int> g_seenDeviceIds;

// Utility...
// Utility for UI navigation
void SingleInputMappingFromPspButton(int btn, std::vector<InputMapping> *mappings, bool ignoreMouse) {
std::vector<MultiInputMapping> 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);
}
}
}

Expand Down Expand Up @@ -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++;

Expand Down Expand Up @@ -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);
}
Expand Down
5 changes: 5 additions & 0 deletions UI/ControlMappingScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit eec1ad5

Please sign in to comment.