mirror of
				https://github.com/libsdl-org/SDL.git
				synced 2025-10-26 12:27:44 +00:00 
			
		
		
		
	Add the platform to the game controller mapping so it can be read back in without changes
Fixes https://github.com/libsdl-org/SDL/issues/4848
This commit is contained in:
		| @@ -1531,16 +1531,17 @@ SDL_GameControllerMappingForIndex(int mapping_index) | ||||
|             char *pMappingString; | ||||
|             char pchGUID[33]; | ||||
|             size_t needed; | ||||
|             const char *platform = SDL_GetPlatform(); | ||||
|  | ||||
|             SDL_JoystickGetGUIDString(mapping->guid, pchGUID, sizeof(pchGUID)); | ||||
|             /* allocate enough memory for GUID + ',' + name + ',' + mapping + \0 */ | ||||
|             needed = SDL_strlen(pchGUID) + 1 + SDL_strlen(mapping->name) + 1 + SDL_strlen(mapping->mapping) + 1; | ||||
|             /* allocate enough memory for GUID + ',' + name + ',' + mapping + platform:PLATFORM + \0 */ | ||||
|             needed = SDL_strlen(pchGUID) + 1 + SDL_strlen(mapping->name) + 1 + SDL_strlen(mapping->mapping) + SDL_strlen(SDL_CONTROLLER_PLATFORM_FIELD) + SDL_strlen(platform) + 1; | ||||
|             pMappingString = SDL_malloc(needed); | ||||
|             if (!pMappingString) { | ||||
|                 SDL_OutOfMemory(); | ||||
|                 return NULL; | ||||
|             } | ||||
|             SDL_snprintf(pMappingString, needed, "%s,%s,%s", pchGUID, mapping->name, mapping->mapping); | ||||
|             SDL_snprintf(pMappingString, needed, "%s,%s,%s%s%s", pchGUID, mapping->name, mapping->mapping, SDL_CONTROLLER_PLATFORM_FIELD, platform); | ||||
|             return pMappingString; | ||||
|         } | ||||
|         --mapping_index; | ||||
| @@ -1559,15 +1560,17 @@ SDL_GameControllerMappingForGUID(SDL_JoystickGUID guid) | ||||
|     if (mapping) { | ||||
|         char pchGUID[33]; | ||||
|         size_t needed; | ||||
|         const char *platform = SDL_GetPlatform(); | ||||
|  | ||||
|         SDL_JoystickGetGUIDString(guid, pchGUID, sizeof(pchGUID)); | ||||
|         /* allocate enough memory for GUID + ',' + name + ',' + mapping + \0 */ | ||||
|         needed = SDL_strlen(pchGUID) + 1 + SDL_strlen(mapping->name) + 1 + SDL_strlen(mapping->mapping) + 1; | ||||
|         /* allocate enough memory for GUID + ',' + name + ',' + mapping + platform:PLATFORM + \0 */ | ||||
|         needed = SDL_strlen(pchGUID) + 1 + SDL_strlen(mapping->name) + 1 + SDL_strlen(mapping->mapping) + SDL_strlen(SDL_CONTROLLER_PLATFORM_FIELD) + SDL_strlen(platform) + 1; | ||||
|         pMappingString = SDL_malloc(needed); | ||||
|         if (!pMappingString) { | ||||
|             SDL_OutOfMemory(); | ||||
|             return NULL; | ||||
|         } | ||||
|         SDL_snprintf(pMappingString, needed, "%s,%s,%s", pchGUID, mapping->name, mapping->mapping); | ||||
|         SDL_snprintf(pMappingString, needed, "%s,%s,%s%s%s", pchGUID, mapping->name, mapping->mapping, SDL_CONTROLLER_PLATFORM_FIELD, platform); | ||||
|     } | ||||
|     return pMappingString; | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Sam Lantinga
					Sam Lantinga