Send gamepad and joystick removed events when quitting

This helps applications do proper cleanup when reinitializing gamepads, e.g. to reset controller mappings
This commit is contained in:
Sam Lantinga
2023-07-18 09:01:14 -07:00
parent 0a4e6f6d29
commit ccefce8321
2 changed files with 37 additions and 17 deletions

View File

@@ -1501,12 +1501,20 @@ void SDL_CloseJoystick(SDL_Joystick *joystick)
void SDL_QuitJoysticks(void)
{
int i;
SDL_JoystickID *joysticks;
SDL_LockJoysticks();
SDL_joysticks_quitting = SDL_TRUE;
/* Stop the event polling */
joysticks = SDL_GetJoysticks(NULL);
if (joysticks) {
for (i = 0; joysticks[i]; ++i) {
SDL_PrivateJoystickRemoved(joysticks[i]);
}
SDL_free(joysticks);
}
while (SDL_joysticks) {
SDL_joysticks->ref_count = 1;
SDL_CloseJoystick(SDL_joysticks);