We found that when multiple controllers are added at once, the order of the joystick instance IDs varies between OS. E.g. Linux and MacOS add them in ascending order, while Windows adds them in descending order. The latter causes problems in our code, especially when adding two or more of the same controller. Then it makes a difference if you add the controllers at once or one by one.
A solution would be to cache the added IDs if they do not follow an ascending order. Only when the cache contains all IDs without a gap to previously added IDs, the code would add the cached IDs, now in ascending order.
Example:
- already added are ID0 + ID1
- ID3 gets added by SDL
- code detects a gap to ID1 and caches ID3
- ID2 gets added by SDL
- code detects that there is no gap to ID1 and adds ID2
- code detects that there is no gap to ID2 and adds ID3
However this will only work if we can make the following assumptions
- IDs are always starting with 0
- IDs have no (permanent) gaps
Are these assumptions valid? Or is there any other option to make sure that the OS adds the IDs in ascending order?
BTW: Does anyone know if the reversed ID order for Windows is an SDL2 for Windows implementation detail or cause by Windows?