Bladeren bron

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
Camilla Löwy 3 jaren geleden
bovenliggende
commit
bfd9eaf092
3 gewijzigde bestanden met toevoegingen van 10 en 0 verwijderingen
  1. 1 0
      CONTRIBUTORS.md
  2. 1 0
      README.md
  3. 8 0
      src/input.c

+ 1 - 0
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

+ 1 - 0
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)
 

+ 8 - 0
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