Skip to content
This repository has been archived by the owner on Mar 30, 2019. It is now read-only.

Commit

Permalink
Update MouseState.cs
Browse files Browse the repository at this point in the history
Fixed incorrect direct copying of returned button array bytes into C# Boolean array. According to this page, https://msdn.microsoft.com/en-us/library/windows/desktop/bb151897(v=vs.85).aspx, the data format states that the value of the byte will be 128 if the button is on and 0 if the button is off. By directly copying the byte value of 128 into a bool, an invalid Boolean is created which initially doesn't cause any problems, but will fail if you bitwise or the bool giving you a value of 129 which evaluates to false when compared to C# true (1). This error also existed in JoystickState in a past version and was updated. The same error in MouseState was never updated however.
  • Loading branch information
augiem authored Aug 15, 2016
1 parent 378f529 commit 5c513e7
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions Source/SharpDX.DirectInput/MouseState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,11 @@ public void MarshalFrom(ref RawMouseState value)
Z = value.Z;

// Copy buttons states
fixed (void* __to = &Buttons[0]) fixed (void* __from = &value.Buttons0) SharpDX.Utilities.CopyMemory((IntPtr)__to, (IntPtr)__from, Buttons.Length);
fixed(void* __from = &value.Buttons0) {
for(int i = 0; i < 8; i++) {
Buttons[i] = (((byte*)__from)[i] & 0x80) != 0;
}
}
}
}

Expand All @@ -61,4 +65,4 @@ public override string ToString()
return string.Format(System.Globalization.CultureInfo.InvariantCulture, "X: {0}, Y: {1}, Z: {2}, Buttons: {3}", X, Y, Z, Utilities.Join(";",Buttons));
}
}
}
}

0 comments on commit 5c513e7

Please sign in to comment.