Don't clobber an existing entry with a different version when adding a gamepad mapping (cherry picked from commit 727c7d4e2f44102bb571180929bfbb5d527f4f27)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
diff --git a/src/joystick/SDL_gamecontroller.c b/src/joystick/SDL_gamecontroller.c
index a8c0dd8..281c3aa 100644
--- a/src/joystick/SDL_gamecontroller.c
+++ b/src/joystick/SDL_gamecontroller.c
@@ -771,7 +771,7 @@ static ControllerMapping_t *SDL_PrivateMatchControllerMappingForGUID(SDL_Joystic
/*
* Helper function to scan the mappings database for a controller with the specified GUID
*/
-static ControllerMapping_t *SDL_PrivateGetControllerMappingForGUID(SDL_JoystickGUID guid, SDL_bool create_mapping)
+static ControllerMapping_t *SDL_PrivateGetControllerMappingForGUID(SDL_JoystickGUID guid, SDL_bool adding_mapping)
{
ControllerMapping_t *mapping;
Uint16 vendor, product, crc;
@@ -791,6 +791,13 @@ static ControllerMapping_t *SDL_PrivateGetControllerMappingForGUID(SDL_JoystickG
return mapping;
}
+ if (adding_mapping) {
+ /* We didn't find an existing mapping */
+ return NULL;
+ }
+
+ /* Try harder to get the best match, or create a mapping */
+
if (vendor && product) {
/* Try again, ignoring the version */
if (crc) {
@@ -806,31 +813,25 @@ static ControllerMapping_t *SDL_PrivateGetControllerMappingForGUID(SDL_JoystickG
}
}
- if (!create_mapping) {
- return NULL;
- }
-
#if SDL_JOYSTICK_XINPUT
if (SDL_IsJoystickXInput(guid)) {
/* This is an XInput device */
return s_pXInputMapping;
}
#endif
- if (mapping == NULL) {
- if (SDL_IsJoystickHIDAPI(guid)) {
- mapping = SDL_CreateMappingForHIDAPIController(guid);
- } else if (SDL_IsJoystickRAWINPUT(guid)) {
- mapping = SDL_CreateMappingForRAWINPUTController(guid);
- } else if (SDL_IsJoystickWGI(guid)) {
- mapping = SDL_CreateMappingForWGIController(guid);
- } else if (SDL_IsJoystickVirtual(guid)) {
- /* We'll pick up a robust mapping in VIRTUAL_JoystickGetGamepadMapping */
+ if (SDL_IsJoystickHIDAPI(guid)) {
+ mapping = SDL_CreateMappingForHIDAPIController(guid);
+ } else if (SDL_IsJoystickRAWINPUT(guid)) {
+ mapping = SDL_CreateMappingForRAWINPUTController(guid);
+ } else if (SDL_IsJoystickWGI(guid)) {
+ mapping = SDL_CreateMappingForWGIController(guid);
+ } else if (SDL_IsJoystickVirtual(guid)) {
+ /* We'll pick up a robust mapping in VIRTUAL_JoystickGetGamepadMapping */
#ifdef __ANDROID__
- } else {
- mapping = SDL_CreateMappingForAndroidController(guid);
-#endif
- }
+ } else {
+ mapping = SDL_CreateMappingForAndroidController(guid);
}
+#endif
return mapping;
}
@@ -1278,7 +1279,7 @@ static ControllerMapping_t *SDL_PrivateAddMappingForGUID(SDL_JoystickGUID jGUID,
}
}
- pControllerMapping = SDL_PrivateGetControllerMappingForGUID(jGUID, SDL_FALSE);
+ pControllerMapping = SDL_PrivateGetControllerMappingForGUID(jGUID, SDL_TRUE);
if (pControllerMapping) {
/* Only overwrite the mapping if the priority is the same or higher. */
if (pControllerMapping->priority <= priority) {
@@ -1340,7 +1341,7 @@ static ControllerMapping_t *SDL_PrivateGetControllerMappingForNameAndGUID(const
SDL_AssertJoysticksLocked();
- mapping = SDL_PrivateGetControllerMappingForGUID(guid, SDL_TRUE);
+ mapping = SDL_PrivateGetControllerMappingForGUID(guid, SDL_FALSE);
#ifdef __LINUX__
if (mapping == NULL && name) {
if (SDL_strstr(name, "Xbox 360 Wireless Receiver")) {
@@ -1777,7 +1778,7 @@ char *SDL_GameControllerMappingForGUID(SDL_JoystickGUID guid)
SDL_LockJoysticks();
{
- ControllerMapping_t *mapping = SDL_PrivateGetControllerMappingForGUID(guid, SDL_TRUE);
+ ControllerMapping_t *mapping = SDL_PrivateGetControllerMappingForGUID(guid, SDL_FALSE);
if (mapping) {
retval = CreateMappingString(mapping, guid);
} else {