| Summary: | [PATCH] Assigning a gamepad the same player index twice sets the wrong index | ||
|---|---|---|---|
| Product: | SDL | Reporter: | Cameron Gutman <cameron.gutman> |
| Component: | joystick | Assignee: | Sam Lantinga <slouken> |
| Status: | RESOLVED FIXED | QA Contact: | Sam Lantinga <slouken> |
| Severity: | normal | ||
| Priority: | P2 | ||
| Version: | HG 2.0 | ||
| Hardware: | x86 | ||
| OS: | Windows 10 | ||
| Attachments: | Fix incorrect player index when assigning a joystick the same index twice | ||
Created attachment 4241 [details]
Fix incorrect player index when assigning a joystick the same index twice
Patch added, thanks! https://hg.libsdl.org/SDL/rev/36aabb2051e9 |
When I call SDL_GameControllerSetPlayerIndex() to set a gamepad to a player index that it happens to already be using, the result is that the gamepad is moved to a new player index that isn't the one I requested. Reproducer: SDL_GameControllerSetPlayerIndex(controller, 0); SDL_GameControllerSetPlayerIndex(controller, 0); The problem is that we hit the following code: /* Move any existing joystick to another slot */ if (existing_instance >= 0) { SDL_SetJoystickIDForPlayerIndex(SDL_FindFreePlayerIndex(), existing_instance); } However, existing_instance == instance_id at that time, so we end up moving the joystick again. We can detect this case earlier to avoid this issue.