Skip to content

Commit

Permalink
Win32: Fix underflow in deadzone logic
Browse files Browse the repository at this point in the history
Fixes #910.
  • Loading branch information
elmindreda committed Dec 19, 2016
1 parent e649708 commit 0f488ac
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
2 changes: 2 additions & 0 deletions README.md
Expand Up @@ -118,6 +118,7 @@ information on what to include when reporting a bug.
- Bugfix: `glfwGetInstanceProcAddress` returned `NULL` for
`vkGetInstanceProcAddr` when `_GLFW_VULKAN_STATIC` was enabled
- [Win32] Bugfix: Undecorated windows could not be iconified by the user (#861)
- [Win32] Bugfix: Deadzone logic could underflow with some controllers (#910)
- [X11] Replaced `_GLFW_HAS_XF86VM` compile-time option with dynamic loading
- [Cocoa] Added support for Vulkan window surface creation via MoltenVK (#870)
- [Cocoa] Bugfix: Disabling window aspect ratio would assert (#852)
Expand Down Expand Up @@ -260,6 +261,7 @@ skills.
- Arthur Tombs
- Ioannis Tsakpinis
- Samuli Tuomola
- Matthew Turner
- urraka
- Elias Vanderstuyft
- Jari Vetoniemi
Expand Down
14 changes: 8 additions & 6 deletions src/win32_joystick.c
Expand Up @@ -603,9 +603,10 @@ static GLFWbool pollJoystickState(_GLFWjoystickWin32* js, int mode)
if (mode == _GLFW_PRESENCE_ONLY)
return GLFW_TRUE;

if (sqrt((double) (xis.Gamepad.sThumbLX * xis.Gamepad.sThumbLX +
xis.Gamepad.sThumbLY * xis.Gamepad.sThumbLY)) >
(double) XINPUT_GAMEPAD_LEFT_THUMB_DEADZONE)
if ((float) xis.Gamepad.sThumbLX * xis.Gamepad.sThumbLX +
(float) xis.Gamepad.sThumbLY * xis.Gamepad.sThumbLY >
(float) XINPUT_GAMEPAD_LEFT_THUMB_DEADZONE *
XINPUT_GAMEPAD_LEFT_THUMB_DEADZONE)
{
js->axes[0] = (xis.Gamepad.sThumbLX + 0.5f) / 32767.f;
js->axes[1] = (xis.Gamepad.sThumbLY + 0.5f) / 32767.f;
Expand All @@ -616,9 +617,10 @@ static GLFWbool pollJoystickState(_GLFWjoystickWin32* js, int mode)
js->axes[1] = 0.f;
}

if (sqrt((double) (xis.Gamepad.sThumbRX * xis.Gamepad.sThumbRX +
xis.Gamepad.sThumbRY * xis.Gamepad.sThumbRY)) >
(double) XINPUT_GAMEPAD_RIGHT_THUMB_DEADZONE)
if ((float) xis.Gamepad.sThumbRX * xis.Gamepad.sThumbRX +
(float) xis.Gamepad.sThumbRY * xis.Gamepad.sThumbRY >
(float) XINPUT_GAMEPAD_RIGHT_THUMB_DEADZONE *
XINPUT_GAMEPAD_RIGHT_THUMB_DEADZONE)
{
js->axes[2] = (xis.Gamepad.sThumbRX + 0.5f) / 32767.f;
js->axes[3] = (xis.Gamepad.sThumbRY + 0.5f) / 32767.f;
Expand Down

0 comments on commit 0f488ac

Please sign in to comment.