From 659f89ea85658e789eafb66d1447617d691d925f Mon Sep 17 00:00:00 2001 From: Clownacy Date: Sat, 4 Apr 2020 19:03:19 +0100 Subject: [PATCH] Cleanup and proper deinitialisation --- src/Backends/GLFW3/Controller.cpp | 9 ++++++++- src/Backends/SDL2/Controller.cpp | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/Backends/GLFW3/Controller.cpp b/src/Backends/GLFW3/Controller.cpp index 1190cf43..20553e1b 100644 --- a/src/Backends/GLFW3/Controller.cpp +++ b/src/Backends/GLFW3/Controller.cpp @@ -1,5 +1,6 @@ #include "../Controller.h" +#include #include #define GLFW_INCLUDE_NONE @@ -58,7 +59,12 @@ static void JoystickCallback(int joystick_id, int event) void ControllerBackend_Deinit(void) { - + glfwSetJoystickCallback(NULL); + + joystick_connected = FALSE; + connected_joystick_id = 0; + joystick_neutral_x = 0; + joystick_neutral_y = 0; } BOOL ControllerBackend_Init(void) @@ -92,6 +98,7 @@ BOOL ControllerBackend_GetJoystickStatus(JOYSTICK_STATUS *status) int total_buttons; const unsigned char *buttons = glfwGetJoystickButtons(connected_joystick_id, &total_buttons); + // The original `Input.cpp` assumed there were 32 buttons (because of DirectInput's `DIJOYSTATE` struct) if (total_buttons > 32) total_buttons = 32; diff --git a/src/Backends/SDL2/Controller.cpp b/src/Backends/SDL2/Controller.cpp index a3434bb5..2072ef20 100644 --- a/src/Backends/SDL2/Controller.cpp +++ b/src/Backends/SDL2/Controller.cpp @@ -67,7 +67,7 @@ BOOL ControllerBackend_GetJoystickStatus(JOYSTICK_STATUS *status) if (joystick == NULL) return FALSE; - // The original Input.cpp assumed there were 32 buttons (because of DirectInput's 'DIJOYSTATE' struct) + // The original `Input.cpp` assumed there were 32 buttons (because of DirectInput's `DIJOYSTATE` struct) int numButtons = SDL_JoystickNumButtons(joystick); if (numButtons > 32) numButtons = 32;