Allegro.cc - Online Community

Allegro.cc Forums » Allegro Development » More than 4 XInput controllers

This thread is locked; no one can reply to it. rss feed Print
 1   2 
More than 4 XInput controllers
Peter Hull
Member #1,136
March 2001

I looked back at my previous posts. I got annoyed, and that wasn't helpful either. A friendly apology to anyone offended, please can we move on?

On the logging data, I am interested in this chunk (edited to simplify)

(PRESSED BUTTON ON ONE CONTROLLER - handle_button_event CALLED FOR BOTH)

[  27.00212] joydx_thread_proc, waker_num = 1, waker handle = 77c
[  27.00230] update 1
[  27.00237] update_joystick 3f0d2748
[  27.00245] handle_button_event 3f0d2748, 0
[  27.00254] joydx_thread_proc, waker_num = 0, waker handle = 6cc
[  27.00264] update 0
[  27.00279] update_joystick 3f0d1fa0
[  27.00286] handle_button_event 3f0d1fa0, 0

In the joystick thread we have an array of event objects, one per joystick, which we're waiting on for events. (here)
Using WaitForMultipleObjects it should return the first (i.e. lowest index) event that was signalled, and, if there is more than one signalled, our code should loop round quickly and pick off each one successively.

Given that, it seems strange that, in the log, we're getting waker_num = 1 and then straight after, waker_num = 0. If joystick 0 had an event, that should have been picked first. I can't figure out why this is.

Andrew, you said (I think) if all joysticks were ready plugged in when the program starts, everything works OK. Can you post the log for that case?

William Labbett
Member #4,486
March 2004
avatar

I can't compile allegro and I wouldn't understand the code much. Good luck guys.
Peace.

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

Peter, there is a one second delay between device scans for new joysticks. Perhaps that is leading to a race condition?

EDIT
Welp. I'm not sure. From the logs Andrew posted, two joysticks are already connected correctly. But pressing a button on one of them causes two joystick button events. Same with release.

Andrew, how are you connecting your joysticks? USB Hub? XBox radio set? Have you tried updating your drivers?

Peter Hull
Member #1,136
March 2001

Peter, there is a one second delay between device scans for new joysticks. Perhaps that is leading to a race condition?

Right, windows sends a WM_DEVICECHANGE but this only sets a flag on the Allegro side here. It is the joystick thread that does the enumeration and this happens at most 1 second later, when WaitForMultipleObjects times out, or maybe earlier if an event from another joystick comes along. Do you agree?
So there may be a race if a joystick is added or removed during an enumeration caused by another event ... maybe ... it makes my head spin.

As I mentioned, the fact that one button press is causing two different event objects to fire is puzzling, especially as they're in the 'wrong' order. Possibly we've set up DirectInput wrong. It would be useful to get a few more data points on the conditions for which it works or doesn't work. For example, does the order matter? Is it 100% repeatable? Is it specific devices or any device? Does it do the same on a different PC?

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

Andrew Gillett
Member #15,868
January 2015

Sorry, again I didn't get an email notification about the new posts. I always call al_reconfigure_joysticks after receiving ALLEGRO_EVENT_JOYSTICK_CONFIGURATION.

I haven't looked at this issue for a while, but as I recall it was always fine if both controllers were connected simultaneously (or already connected on startup). If the two controllers were connected several seconds apart, the problem would occur, regardless of which was connected first. I don't remember if one of the two controllers would consistently steal the input of the other, or if it was sometimes the other way around.

The controllers were usually both connected through a hub, although I don't think it made a difference if they were connected to other ports.

The situation regarding my game has changed, in that the Steam Input fix for 5+ XInput controller is now not due until January. So what I'm currently trying to do is getting it to work with DirectInput, while hoping the bug under discussion is a freak event which is just specific to one type of 3rd party Xbox controller. The next problem is that, running in DirectInput mode, my game does not see remote controllers connected through Remote Play Together. Steam have sent me some guidance on this - they said their software sends the game a WM_INPUT_DEVICE_CHANGE message when a remote controller is connected. I added a check for that alongside the WM_DEVICECHANGE check, but the message never seems to be received. The other thing they told me to try is to periodically rescan controllers regardless of any messages receieved. When I did that, the first time the game completely froze the host's PC (no idea if this is an Allegro or Steam issue), the second time it didn't crash and I saw stuff like this in the log:

dinput   D         wjoydxnu.cpp:1078 joydx_scan                       [ 152.06037] 
dinput   D         wjoydxnu.cpp:1085 joydx_scan                       [ 152.06047] Calling IDirectInput8_EnumDevices
dinput   D         wjoydxnu.cpp:827  joystick_enum_callback           [ 152.06050] joystick_enum_callback
dinput   D         wjoydxnu.cpp:967  joystick_enum_callback           [ 152.06059] waker_event: 560
dinput   E         wjoydxnu.cpp:975  joystick_enum_callback           [ 152.06062] SetEventNotification failed for joystick 0: unknown error
dinput   D         wjoydxnu.cpp:1095 joydx_scan                       [ 152.43871] Completed IDirectInput8_EnumDevices
dinput   D         wjoydxnu.cpp:1078 joydx_scan                       [ 153.43842] 
dinput   D         wjoydxnu.cpp:1085 joydx_scan                       [ 153.43850] Calling IDirectInput8_EnumDevices
dinput   D         wjoydxnu.cpp:827  joystick_enum_callback           [ 153.43854] joystick_enum_callback
dinput   D         wjoydxnu.cpp:967  joystick_enum_callback           [ 153.43862] waker_event: 544
dinput   E         wjoydxnu.cpp:975  joystick_enum_callback           [ 153.43864] SetEventNotification failed for joystick 0: unknown error
dinput   D         wjoydxnu.cpp:1095 joydx_scan                       [ 153.60105] Completed IDirectInput8_EnumDevices
dinput   D         wjoydxnu.cpp:1078 joydx_scan                       [ 154.60045] 
dinput   D         wjoydxnu.cpp:1085 joydx_scan                       [ 154.60054] Calling IDirectInput8_EnumDevices
dinput   D         wjoydxnu.cpp:827  joystick_enum_callback           [ 154.60057] joystick_enum_callback
dinput   D         wjoydxnu.cpp:967  joystick_enum_callback           [ 154.60065] waker_event: 568
dinput   E         wjoydxnu.cpp:975  joystick_enum_callback           [ 154.60068] SetEventNotification failed for joystick 0: unknown error
dinput   D         wjoydxnu.cpp:1095 joydx_scan                       [ 154.66114] Completed IDirectInput8_EnumDevices

I will message Steam about the SetEventNotification failure, but is looks unlikely it will be possible to fix this within the next 24 hours which is what would be necessary to release on time. So I expect to have to wait for Steam to fix the issues with Steam Input, and my game will be delayed by several weeks. This isn't a disaster for me, especially as I don't expect the game to sell many copies either way.

UPDATE

I got the following response from Steam:

Quote:

The overlay will only generate WM_INPUT and WM_INPUT_DEVICE_CHANGED callbacks when you've called RegisterRawInputDevices.

It doesn't look like we implement the IDirectInputDevice8_SetEventNotification function in the overlay. I believe you'd have to either poll the device state or key off of WM_INPUT messages instead.

I added a call to RegisterRawInputDevices - wasn't sure where to put it, so I put it in _al_win_init_window. I used the code from Example 1 here https://docs.microsoft.com/en-us/windows/win32/inputdev/using-raw-input - but without including the second two device categories and using RIDEV_DEVNOTIFY as the flags. I then hacked joystick_enum_callback to assume that a device which triggers "unknown error" from IDirectInputDevice8_SetEventNotification is a Steam emulated controller, and therefore set it to act as a polled device. This probably isn't a very safe assumption but I wanted to see if this would allow it to work. What I found is that Remote Play Together can now see XBox 360 controllers, but not 3rd party DirectInput controllers. And I found that not all of the connected XBox 360 controllers actually worked, ie the game did not receive their control inputs.

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

Andrew Gillett
Member #15,868
January 2015

The Steam client beta now has an option (Xbox Extended Feature Support) to install a driver which provides support for 5+ XInput controllers. There are still some teething problems but it generally seems to work for me. It's not clear when it will come out of beta, but my game will be releasing on Jan 29 regardless. One of the nice things about using the Steam Input API is that it supports PS3/4 and Switch Pro controllers. So people doing games to be released on Steam should certainly consider it.

My game's store page:
https://store.steampowered.com/app/1068720/Partition_Sector/

Peter Hull
Member #1,136
March 2001

Any more updates on this?

Andrew Gillett
Member #15,868
January 2015

The game is out now. Steam Input support for 5+ XInput controllers remains in beta. Steam uses SDL, there is a discussion on the issue here although it is quite old so may not be fully up-to-date.
https://discourse.libsdl.org/t/supporting-more-than-4-xinput-capable-devices-on-windows-rfc/25666/13

 1   2 


Go to: