Skip to content

Commit

Permalink
Don't overwrite non-CRC gamepad mapping with a new mapping that speci…
Browse files Browse the repository at this point in the history
…fies a CRC

Fixes libsdl-org#11723

(cherry picked from commit 1413bfb)
(cherry picked from commit ddfdb0c)
  • Loading branch information
slouken committed Dec 27, 2024
1 parent 1c3ad75 commit ea873d3
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/joystick/SDL_gamecontroller.c
Original file line number Diff line number Diff line change
Expand Up @@ -688,7 +688,7 @@ static ControllerMapping_t *SDL_CreateMappingForWGIController(SDL_JoystickGUID g
/*
* Helper function to scan the mappings database for a controller with the specified GUID
*/
static ControllerMapping_t *SDL_PrivateMatchControllerMappingForGUID(SDL_JoystickGUID guid, SDL_bool match_version)
static ControllerMapping_t *SDL_PrivateMatchControllerMappingForGUID(SDL_JoystickGUID guid, SDL_bool match_version, SDL_bool exact_match_crc)
{
ControllerMapping_t *mapping, *best_match = NULL;
Uint16 crc = 0;
Expand Down Expand Up @@ -728,9 +728,10 @@ static ControllerMapping_t *SDL_PrivateMatchControllerMappingForGUID(SDL_Joystic

/* An exact match, including CRC */
return mapping;
} else if (crc && exact_match_crc) {
return NULL;
}


if (!best_match) {
best_match = mapping;
}
Expand All @@ -746,7 +747,7 @@ static ControllerMapping_t *SDL_PrivateGetControllerMappingForGUID(SDL_JoystickG
{
ControllerMapping_t *mapping;

mapping = SDL_PrivateMatchControllerMappingForGUID(guid, SDL_TRUE);
mapping = SDL_PrivateMatchControllerMappingForGUID(guid, SDL_TRUE, adding_mapping);
if (mapping) {
return mapping;
}
Expand All @@ -760,7 +761,7 @@ static ControllerMapping_t *SDL_PrivateGetControllerMappingForGUID(SDL_JoystickG

if (SDL_JoystickGUIDUsesVersion(guid)) {
/* Try again, ignoring the version */
mapping = SDL_PrivateMatchControllerMappingForGUID(guid, SDL_FALSE);
mapping = SDL_PrivateMatchControllerMappingForGUID(guid, SDL_FALSE, SDL_FALSE);
if (mapping) {
return mapping;
}
Expand Down

0 comments on commit ea873d3

Please sign in to comment.