From d834c08ac77e33d76d0ad4a6a140a8392c2489fc Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Tue, 29 Nov 2016 22:02:37 -0800 Subject: [PATCH] Add the controller mappings to the linked list in order --- src/joystick/SDL_gamecontroller.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/joystick/SDL_gamecontroller.c b/src/joystick/SDL_gamecontroller.c index 3d9d967a2d872..b304f6ad493a5 100644 --- a/src/joystick/SDL_gamecontroller.c +++ b/src/joystick/SDL_gamecontroller.c @@ -692,9 +692,22 @@ SDL_PrivateAddMappingForGUID(SDL_JoystickGUID jGUID, const char *mappingString, pControllerMapping->guid = jGUID; pControllerMapping->name = pchName; pControllerMapping->mapping = pchMapping; - pControllerMapping->next = s_pSupportedControllers; + pControllerMapping->next = NULL; pControllerMapping->priority = priority; - s_pSupportedControllers = pControllerMapping; + + if (s_pSupportedControllers) { + /* Add the mapping to the end of the list */ + ControllerMapping_t *pCurrMapping, *pPrevMapping; + + for ( pPrevMapping = s_pSupportedControllers, pCurrMapping = pPrevMapping->next; + pCurrMapping; + pPrevMapping = pCurrMapping, pCurrMapping = pCurrMapping->next ) { + continue; + } + pPrevMapping->next = pControllerMapping; + } else { + s_pSupportedControllers = pControllerMapping; + } *existing = SDL_FALSE; } return pControllerMapping;