From b8182817e401399c63c776318f3fba577681fab3 Mon Sep 17 00:00:00 2001 From: gilzoide Date: Sun, 7 Feb 2021 09:25:05 -0300 Subject: [PATCH] Fix initialize GLFW's Joystick subsystem before window is created on Desktop platforms (#1554) --- src/core.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/core.c b/src/core.c index 20fb06f6f..5bf818b4f 100644 --- a/src/core.c +++ b/src/core.c @@ -3321,6 +3321,20 @@ static bool InitGraphicsDevice(int width, int height) #endif } +#if defined(PLATFORM_DESKTOP) + // NOTE: GLFW 3.4+ defers initialization of the Joystick subsystem on the + // first call to any Joystick related functions. Forcing this + // initialization here avoids doing it on `PollInputEvents` called by + // `EndDrawing` after first frame has been just drawn. The initialization + // will still happen and possible delays still occur, but before the window + // is shown, which is a nicer experience. + // Ref: https://github.com/raysan5/raylib/issues/1554 + if (MAX_GAMEPADS > 0) + { + glfwSetJoystickCallback(NULL); + } +#endif // PLATFORM_DESKTOP + if (CORE.Window.fullscreen) { // remember center for switchinging from fullscreen to window