Checking for HIDAPI on Windows with latest SDK + VS tools slows event loop

A strange one this - I noticed I was getting a periodic but regular glitch in my video application built on SDL2/vlc but only when I built SDL from the latest Windows 10 SDK + build tools. My older build from (I think) the previous Windows 10 SDK doesn’t exhibit the problem.

Basically in the main event loop what looked like every three seconds it would pause briefly, i.e. all event processing would be delayed by an additional 50-60ms or so.

So as a random idea I searched in the SDL code for the value 3000 and found that in the HIDAPI code it checks this often for new controllers. I changed this to 30,000 and lo-and-behold my glitch became every 30s instead.

I’ve now disabled HIDAPI in my build as I do not need it anyway, so this is a heads-up more than anything else.

Perhaps things like this could be performed in background threads and post an event to indicate when a controller is added/removed etc? There is already the problem with SDL where you have to do all the rendering in the main loop, so I think the event loop needs to be as slim/unbloated as possible.

1 Like

This is a known bug in SDL2 2.0.9, it’s fixed in hg, a workaround is to pass SDL_INIT_JOYSTICK to SDL_Init() (it has nothing to do with the Win SDK version).

Ok thanks. There is some factor involving the SDK or version of VS because my build of 2.0.9 from back in November doesn’t show this issue, but when I rebuild the same code it does.

Ok, that’s weird - maybe when using that SDK code HIDAPI was disabled for some reason?
No idea…

Does the workaround help at least? :slight_smile:

Thank you Daniel, I appreciate the workaround. It is good to know although I haven’t tried it yet as I don’t need the HIDAPI support in any case.

For anyone else who comes across this issue, I found the record of the bug referred to by Daniel:

The proper bugreport for this is the one you linked is most probably a duplicate.
If you build SDL2 yourself anyway, just use latest hg code instead of 2.0.9