From df7a55911df5e84bd6eb46cebd48220b7305c62a Mon Sep 17 00:00:00 2001 From: Sasha Szpakowski Date: Sat, 17 Jun 2023 22:16:18 -0300 Subject: [PATCH] Fix love.joystick.setGamepadMapping breaking the mapping string when replacing an existing binding. issue #1936. --- src/modules/joystick/sdl/JoystickModule.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/modules/joystick/sdl/JoystickModule.cpp b/src/modules/joystick/sdl/JoystickModule.cpp index dd5d3bf2a..d979fc02b 100644 --- a/src/modules/joystick/sdl/JoystickModule.cpp +++ b/src/modules/joystick/sdl/JoystickModule.cpp @@ -259,12 +259,17 @@ bool JoystickModule::setGamepadMapping(const std::string &guid, Joystick::Gamepa if (endpos == std::string::npos) endpos = mapstr.length() - 1; - mapstr.replace(findpos + 1, endpos - findpos + 1, insertstr); + mapstr.replace(findpos + 1, endpos - findpos, insertstr); } else { - // Just append to the end if we don't need to replace anything. - mapstr += insertstr; + // Just append to the end (or before the platform section if that exists), + // if we don't need to replace anything. + size_t platformpos = mapstr.find("platform:"); + if (platformpos != std::string::npos) + mapstr.insert(platformpos, insertstr); + else + mapstr += insertstr; } // 1 == added, 0 == updated, -1 == error.