Cxbx-reloaded: DirectInput controllers don't work

Created on 23 Aug 2018  Â·  5Comments  Â·  Source: Cxbx-Reloaded/Cxbx-Reloaded

Ever since the new settings manager has been added, my dinput controllers don’t work anymore with cxbxr and the log says it cannot find the mapped controller even though it is attached and configured. Initially, I tracked down the issue to the WrapEnumGameCtrlCallback function: lpddi->tszInstanceName has an extra space at the end which the stored name in the settings doesn’t have (in my case, “USB Gamepad ” vs “USB Gamepad”), which causes strncmp inside DeviseIsUsed to fail and marks the device as not used, hence the problem. However, I also discovered that if I add the missing space (with VS debugger) to m_settings.DeviceName (which stores the device name read from the settings file), then dinput successfully enumerates the controller but the polling function fails on it for some reason. Either other parameters are read incorrectly or the logic was somehow broken during the implementation of the new manager. This also needs to be reproduced since no one else has yet reported the problem, which could mean that either is problem on my end or nobody else uses dinput controllers.

bug input

Most helpful comment

I tested with my dinput controller and confirmed that now it works. Great.

All 5 comments

I suspect this issue is related to the specific controller @ergo720 is using: Other DirectInput controllers with a device name that does NOT end in a space, are likely fine.

The issue seems to stem from the fact that SimpleIni automatically trims trailing spaces away from values, when reading and writing them. This means that the space at the end of the Device Name (which SHOULD be present for this device) is removed by SimpleIni.

A potential fix would be by storing the string in the settings ini surrounded by Quotes: that way, the space character will be inside quotes and won't be stripped away. The ini reading code would then need to remove the quotes to retrieve the original value.

I can confirm the issue came from SimpleIni class. Since SimpleIni implemented a trim spaces around a key/value. Using quotes, as LukeUsher said, is the solution. I'll implement a fix. However, it will not be backward compatibility with an older build of Cxbx-Reloaded.

@ergo720, can you confirm pull request #1407 works for your affecting controller? If it works, feel free to merge it.

I tested with my dinput controller and confirmed that now it works. Great.

@RadWolfie thanks for the speedy resolution

Was this page helpful?
0 / 5 - 0 ratings