mirror of https://github.com/encounter/SDL.git
Add new virtual joysticks to the end of the list
This guarantees that the device index that's returned is stable, as long as no joystick hotplug events occur.
This commit is contained in:
parent
3c3ccb1d48
commit
1f2a241688
|
@ -245,8 +245,16 @@ SDL_JoystickAttachVirtualInner(const SDL_VirtualJoystickDesc *desc)
|
||||||
hwdata->instance_id = SDL_GetNextJoystickInstanceID();
|
hwdata->instance_id = SDL_GetNextJoystickInstanceID();
|
||||||
|
|
||||||
/* Add virtual joystick to SDL-global lists */
|
/* Add virtual joystick to SDL-global lists */
|
||||||
hwdata->next = g_VJoys;
|
if (g_VJoys) {
|
||||||
g_VJoys = hwdata;
|
joystick_hwdata *last;
|
||||||
|
|
||||||
|
for (last = g_VJoys; last->next; last = last->next) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
last->next = hwdata;
|
||||||
|
} else {
|
||||||
|
g_VJoys = hwdata;
|
||||||
|
}
|
||||||
SDL_PrivateJoystickAdded(hwdata->instance_id);
|
SDL_PrivateJoystickAdded(hwdata->instance_id);
|
||||||
|
|
||||||
/* Return the new virtual-device's index */
|
/* Return the new virtual-device's index */
|
||||||
|
|
|
@ -365,7 +365,7 @@ static void CloseVirtualController()
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for (i = 0; i < SDL_NumJoysticks(); ++i) {
|
for (i = SDL_NumJoysticks(); i--; ) {
|
||||||
if (SDL_JoystickIsVirtual(i)) {
|
if (SDL_JoystickIsVirtual(i)) {
|
||||||
SDL_JoystickDetachVirtual(i);
|
SDL_JoystickDetachVirtual(i);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue