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 74a8ba26c3.

This change was backported without taking into account that 3.3.x does
not have on-demand joystick init.

Fixes #1996
This commit is contained in:
Camilla Löwy 2021-11-24 23:09:24 +01:00
parent 6902435005
commit bfd9eaf092
3 changed files with 10 additions and 0 deletions

View File

@ -209,6 +209,7 @@ video tutorials.
- Richard A. Wilkes
- Tatsuya Yatagawa
- Ryogo Yoshimura
- Rácz Zalán
- Lukas Zanner
- Andrey Zholos
- Aihui Zhu

View File

@ -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)

View File

@ -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