Răsfoiți Sursa

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 ani în urmă
părinte
comite
bfd9eaf092
3 a modificat fișierele cu 10 adăugiri și 0 ștergeri
  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
  - Richard A. Wilkes
  - Tatsuya Yatagawa
  - Tatsuya Yatagawa
  - Ryogo Yoshimura
  - Ryogo Yoshimura
+ - Rácz Zalán
  - Lukas Zanner
  - Lukas Zanner
  - Andrey Zholos
  - Andrey Zholos
  - Aihui Zhu
  - Aihui Zhu

+ 1 - 0
README.md

@@ -123,6 +123,7 @@ information on what to include when reporting a bug.
 
 
 ## Changelog
 ## Changelog
 
 
+ - Bugfix: Joysticks connected before init did not get gamepad mappings (#1996)
  - [Cocoa] Bugfix: A dependency on an external constant caused crashes on macOS
  - [Cocoa] Bugfix: A dependency on an external constant caused crashes on macOS
    11 and earlier (#1985,#1994)
    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)
 void _glfwInitGamepadMappings(void)
 {
 {
+    int jid;
     size_t i;
     size_t i;
     const size_t count = sizeof(_glfwDefaultMappings) / sizeof(char*);
     const size_t count = sizeof(_glfwDefaultMappings) / sizeof(char*);
     _glfw.mappings = calloc(count, sizeof(_GLFWmapping));
     _glfw.mappings = calloc(count, sizeof(_GLFWmapping));
@@ -410,6 +411,13 @@ void _glfwInitGamepadMappings(void)
         if (parseMapping(&_glfw.mappings[_glfw.mappingCount], _glfwDefaultMappings[i]))
         if (parseMapping(&_glfw.mappings[_glfw.mappingCount], _glfwDefaultMappings[i]))
             _glfw.mappingCount++;
             _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
 // Returns an available joystick object with arrays and name allocated