libsdl-org/sdl2-compat

Remaining device index vs instance work

icculus opened this issue · 0 comments

There are a few places we still need to deal with device indexes that we currently don't:

  • Device add events are meant to supply an index in SDL2; it's an instance in SDL3.
  • JoystickAttachVirtual and JoystickDetachVirtual deal with indices in SDL2.
  • Audio devices need to be tracked in SDL2 now that this has changed in SDL3.

(Eventually we'll be doing the same thing with audio, but we'll deal with that separately, since this hasn't changed in SDL3 yet afaik.)

Right now we are just keeping a list of device instances that only changes when someone calls SDL_NumJoysticks, etc, so the indices are stable, but we'll have to append new items to the end of the list between calls (and check exactly what the behavior on this is in real SDL2 when adding virtual joysticks, etc).

My thinking is that we won't try to adjust the array when a device is removed, so indices stay stable until the next SDL_NumJoysticks call; if an app tries to use that device, it'll correctly fail because the underlying device instance value will be bogus, but nothing will explode.