No SDL_JOYDEVICEADDED events

Hi,

I’m using SDL v2.0.5 on Windows and I’m trying to detect when joystick devices are added or removed. I’ve init’d SDL with:

SDL_Init(SDL_INIT_VIDEO | SDL_INIT_EVENTS)

and later:

SDL_InitSubSystem(SDL_INIT_GAMECONTROLLER)

Currently I see no device added/removed events. I’m not using the SDL event loop… using SDL_PeepEvent() instead. Input works, joysticks work, game controllers work… everything works except I see no device added/removed events.

What am I missing?

Thanks,

Ed

I’m not using the SDL event loop…

Is there a reason not to?

Put a call to SDL_PumpEvents() in right before your call to SDL_PeepEvent() and see if it starts working.

Actually I already use SDL_PumpEvents()… but polling mode for joysticks instead of axis/button/etc. events.

– Ed

Hmm, okay…I’ll check this on Windows and see what’s up. Is there source code somewhere I can look at?

(If you want to try this before I get back to the office: try test/testhotplug.c in the SDL source tree, so we can see if it’s just completely broken.)

From what I can tell, the testhotplug program sees no events either.

– Ed

Hi Ryan,

My code is closed, so I can’t make it availble. Despite that, the events appear to be broken in the testhotplug program for me as well… any ideas? Is it working for you in v2.0.5 on Windows?

Thanks,

– Ed

Is it working for you in v2.0.5 on Windows?

I’ll be testing soon. It works on macOS, so it’s not a generic SDL bug, but it’s totally possible we broke it on Windows. I’ll report back soon and we can figure out what to do from there.

  Is it working for you in v2.0.5 on Windows?

I’ll be testing soon. It works on macOS, so it’s not a generic SDL bug,
but it’s totally possible we broke it on Windows. I’ll report back soon
and we can figure out what to do from there.

Let me know if there’s anything I can try. I haven’t built my own copy of
SDL v2.0.5 (yet, I’m unfamiliar with the process), but I could try to do
that and “turn on debugging” or whatever we would need to do to track this
down.

Thanks, Ryan!

It works here. :confused:

Are you trying to plug in an XBox controller by any chance? If so, is there a chance your SDL build doesn’t have XInput support?

–ryan.

Hey Ryan,

I successfully compiled v2.0.5 from scratch, got the joystick test working
and the add/remove device events showed up fine (what???), then tried
using this new v2.0.5 build with my code… and it still didn’t work
(what?!?!?!).

When I was (incompentently) trying to describe that I’m not using joystick
events for the input readings (I’m using direct readings instead), I was
forgetting that these input events get ignored and avoided in the event
queue using SDL_JoystickEventState(SDL_DISABLE).

So then I looked at SDL_JoystickEventState() in the SDL source and
discovered how the device events were rolled in together with all the
input events, so my SDL_JoystickEventState(SDL_DISABLE) call was in fact
disabling the device added/removed events as well. <>

So I added code to specifically re-enable the XXXDEVICEADDED/REMOVED
events… and of course it all started working as expected.

Sorry for taking up your time on this.

Ed
1 Like

Glad you figured it out!