From bfd9eaf0926320493f5257e9d57bf5d4f3c5cc53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camilla=20L=C3=B6wy?= Date: Wed, 24 Nov 2021 23:09:24 +0100 Subject: [PATCH] Fix mappings for gamepads present at init Joysticks already connected when GLFW was initalized did not get gamepad mappings applied to them. Regression introduced by 74a8ba26c3b9bb830462ffbebefa133c38368fa3. This change was backported without taking into account that 3.3.x does not have on-demand joystick init. Fixes #1996 --- CONTRIBUTORS.md | 1 + README.md | 1 + src/input.c | 8 ++++++++ 3 files changed, 10 insertions(+) diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index 0b659e83..6b89662a 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -209,6 +209,7 @@ video tutorials. - Richard A. Wilkes - Tatsuya Yatagawa - Ryogo Yoshimura + - Rácz Zalán - Lukas Zanner - Andrey Zholos - Aihui Zhu diff --git a/README.md b/README.md index 635ffff2..19f91673 100644 --- a/README.md +++ b/README.md @@ -123,6 +123,7 @@ information on what to include when reporting a bug. ## Changelog + - Bugfix: Joysticks connected before init did not get gamepad mappings (#1996) - [Cocoa] Bugfix: A dependency on an external constant caused crashes on macOS 11 and earlier (#1985,#1994) diff --git a/src/input.c b/src/input.c index 67919334..96930240 100644 --- a/src/input.c +++ b/src/input.c @@ -401,6 +401,7 @@ void _glfwInputJoystickHat(_GLFWjoystick* js, int hat, char value) // void _glfwInitGamepadMappings(void) { + int jid; size_t i; const size_t count = sizeof(_glfwDefaultMappings) / sizeof(char*); _glfw.mappings = calloc(count, sizeof(_GLFWmapping)); @@ -410,6 +411,13 @@ void _glfwInitGamepadMappings(void) if (parseMapping(&_glfw.mappings[_glfw.mappingCount], _glfwDefaultMappings[i])) _glfw.mappingCount++; } + + for (jid = 0; jid <= GLFW_JOYSTICK_LAST; jid++) + { + _GLFWjoystick* js = _glfw.joysticks + jid; + if (js->present) + js->mapping = findValidMapping(js); + } } // Returns an available joystick object with arrays and name allocated