We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 4048

Summary: XINPUT_STATE_EX does not exist
Product: SDL Reporter: Andrew Eikum <aeikum>
Component: joystickAssignee: Sam Lantinga <slouken>
Status: WAITING --- QA Contact: Sam Lantinga <slouken>
Severity: minor    
Priority: P2    
Version: HG 2.1   
Hardware: All   
OS: All   
Attachments: Patch to remove XINPUT_STATE_EX

Description Andrew Eikum 2018-01-16 14:47:50 UTC
Created attachment 3141 [details]
Patch to remove XINPUT_STATE_EX

This revision introduced the XINPUT_STATE_EX and XINPUT_GAMEPAD_EX structs, which are identical to XINPUT_STATE and XINPUT_GAMEPAD, but add an extra 4 bytes for "padding":

  changeset:   6690:9548c8a58103
  user:        Sam Lantinga <slouken@libsdl.org>
  date:        Mon Nov 26 16:37:54 2012 -0800
  summary:     Added hotplug joystick support and simplified game controller API, courtesy of Alfred Reynolds

As far as I can tell, these structs do not exist in the win32 API. Tests against Microsoft's xinput DLLs show that it never writes to this padding field.

These bogus structs have been copied into mumble-voip[1] and into Wine[2] and from there into mingw-w64. It actually caused a bug in Wine due to our writing into the padding field, which the application never allocated, because it doesn't exist.

To stem the spread of these structs and prevent confusion, I suggest eliminating these structs from SDL. I've attached a diff here that eliminates them from libSDL. Note that I didn't regenerate configure and other build files, as I'm not familiar with your build system.

If you desire to keep the EX versions for type safety reasons, then I suggest eliminating the dwPaddingReserved field.

See also my thread on the Discourse[3].

I suspect the same may be true of XINPUT_BATTERY_INFORMATION_EX, but I didn't test this struct against Microsoft's implementation.

[1] https://github.com/mumble-voip/mumble/issues/2018

[2] https://source.winehq.org/git/wine.git/blob/wine-3.0-rc6:/include/xinput.h#l173

[3] https://discourse.libsdl.org/t/sdl-archaeology-where-does-xinput-gamepad-ex-come-from/23714
Comment 1 Sam Lantinga 2018-01-16 20:09:41 UTC
I believe this struct is used with the undocumented XInputGetStateEx() function (ordinal 100)

Have you tried verifying that?
Comment 2 Andrew Eikum 2018-01-17 13:45:04 UTC
Yes, that's what I tested with. I set dwPaddingReserved to some value, called that function, and verified that it still had the original value afterwards. Additionally, real win32 apps do not allocate memory for dwPaddingReserved before calling ordinal 100, and they do not crash.