sharpdx / SharpDX

SharpDX GitHub Repository
http://sharpdx.org
MIT License
1.69k stars 641 forks source link

Wrong button int value #961

Open Zayceur opened 6 years ago

Zayceur commented 6 years ago

Hello,

I just found that SharpDX.XInput.GamepadButtonFlags.Y has a value of -32768 instead of 32768.

Is that a bug or not ?

Thanks a lot.

Zayceur

Gavin-Williams commented 6 years ago

Yes, that looks like a bug to me.

xoofx commented 6 years ago

I just found that SharpDX.XInput.GamepadButtonFlags.Y has a value of -32768 instead of 32768.

I don't understand the problem. If you look at the XINPUT_GAMEPAD documentation, you will see that the values are a short and hence ranging from -32768 to 32767

Gavin-Williams commented 6 years ago

In the GamepadButtonFlags enum Y = short.MinValue, but it should be Y = 32768 and listed at the end of the enum, after X=16384. I don't think I can fix this as it might be auto-generated code. My understanding of how SharpDX works is limited, and so when I search for 'GamepadButtonFlags' in the repo, nothing comes back except for the line ..

\<map enum="XINPUT_GAMEPAD_BUTTON_FLAGS" name="GamepadButtonFlags" flags="true" none="true" type="short"/>

Here's the offending code in SharpDX library..

namespace SharpDX.XInput { [Flags] public enum GamepadButtonFlags : short // <- should be word (ushort) { Y = short.MinValue, // <- This is incorrect, move to the bottom and revalue None = 0, DPadUp = 1, ... A = 4096, B = 8192, X = 16384 // <- Here is where Y = 32768 is missing } }

Also, note that the enum should be ushort rather than short to match wButton (word) and to fit the Y value. This may be where the problem originated, trying to fit the enum into short, and Y was rejigged.

Gavin-Williams commented 6 years ago

I've proposed a pull request to fix this: https://github.com/sharpdx/SharpDX/pull/963