From 0f488ac2865d766155344fb356acb40007421ec8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camilla=20L=C3=B6wy?= Date: Mon, 19 Dec 2016 05:38:33 +0100 Subject: [PATCH] Win32: Fix underflow in deadzone logic Fixes #910. --- README.md | 2 ++ src/win32_joystick.c | 14 ++++++++------ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index eb09c967..9ba95d99 100644 --- a/README.md +++ b/README.md @@ -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) @@ -260,6 +261,7 @@ skills. - Arthur Tombs - Ioannis Tsakpinis - Samuli Tuomola + - Matthew Turner - urraka - Elias Vanderstuyft - Jari Vetoniemi diff --git a/src/win32_joystick.c b/src/win32_joystick.c index 076bb046..96f907bc 100644 --- a/src/win32_joystick.c +++ b/src/win32_joystick.c @@ -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; @@ -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;