diff --git a/core/input/input.cpp b/core/input/input.cpp index af28774c669..676d1de9708 100644 --- a/core/input/input.cpp +++ b/core/input/input.cpp @@ -1602,9 +1602,6 @@ void Input::parse_mapping(const String &p_mapping) { return; } - CharString uid; - uid.resize(17); - mapping.uid = entry[0]; mapping.name = entry[1]; @@ -1712,44 +1709,29 @@ void Input::add_joy_mapping(const String &p_mapping, bool p_update_existing) { } void Input::remove_joy_mapping(const String &p_guid) { - int fallback_mapping_offset = 0; // Fix the fallback, if we invalidate its index. + int index_removed = 0; for (int i = map_db.size() - 1; i >= 0; i--) { if (p_guid == map_db[i].uid) { map_db.remove_at(i); + index_removed = i; if (i == fallback_mapping) { fallback_mapping = -1; WARN_PRINT_ONCE(vformat("Removed fallback joypad input mapping \"%s\". This could lead to joypads not working as intended.", p_guid)); - } else if (i < fallback_mapping) { - fallback_mapping_offset--; } } } - if (fallback_mapping_offset < 0) { - fallback_mapping += fallback_mapping_offset; - } - for (KeyValue &E : joy_names) { Joypad &joy = E.value; - int mapping; if (joy.uid == p_guid) { - mapping = -1; - } else if (joy.mapping == (fallback_mapping - fallback_mapping_offset)) { - // Fix the mapping for the joypad that uses an outdated fallback index. - mapping = fallback_mapping; - } else { - // Re-validate the joypad's correct mapping. Fix it if necessary. - mapping = fallback_mapping; - for (int i = 0; i < map_db.size(); i++) { - if (joy.uid == map_db[i].uid) { - mapping = i; - } - } + _set_joypad_mapping(joy, -1); + } else if (joy.mapping > index_removed) { + // The map_db update offset this joypad's mapping reference, update it: + _set_joypad_mapping(joy, map_db[joy.mapping - 1]); } - _set_joypad_mapping(joy, mapping); } }