From 1237142be3065c05a3f1c2fe99843d28474b159e Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Thu, 18 Nov 2021 19:52:34 -0600 Subject: [PATCH] joystick: Quit drivers in reverse order to ensure dependencies are not broken SDL_WINDOWS_JoystickDriver depends on callbacks in SDL_RAWINPUT_JoystickDriver and SDL_HIDAPI_JoystickDriver being available. It also manages the common WindowProc used for joystick detection in both WINDOWS and RAWINPUT drivers. If we don't tear them down backwards, there's a window of time where we could invoke RAWINPUT_WindowProc() after RAWINPUT_JoystickQuit() was called. --- src/joystick/SDL_joystick.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/joystick/SDL_joystick.c b/src/joystick/SDL_joystick.c index 8143da250..95f241bc4 100644 --- a/src/joystick/SDL_joystick.c +++ b/src/joystick/SDL_joystick.c @@ -1131,8 +1131,8 @@ SDL_JoystickQuit(void) SDL_JoystickClose(SDL_joysticks); } - /* Quit the joystick setup */ - for (i = 0; i < SDL_arraysize(SDL_joystick_drivers); ++i) { + /* Quit drivers in reverse order to avoid breaking dependencies between drivers */ + for (i = SDL_arraysize(SDL_joystick_drivers) - 1; i >= 0; --i) { SDL_joystick_drivers[i]->Quit(); }