Add joystick locking for controller notifications on iOS/tvOS

Fixes https://github.com/libsdl-org/SDL/issues/6288
main
Sam Lantinga 2022-09-27 12:58:16 -07:00
parent 18eb319adc
commit 7becbd7d42
1 changed files with 6 additions and 3 deletions

View File

@ -678,7 +678,9 @@ IOS_JoystickInit(void)
queue:nil
usingBlock:^(NSNotification *note) {
GCController *controller = note.object;
SDL_LockJoysticks();
IOS_AddJoystickDevice(controller, SDL_FALSE);
SDL_UnlockJoysticks();
}];
disconnectObserver = [center addObserverForName:GCControllerDidDisconnectNotification
@ -686,14 +688,15 @@ IOS_JoystickInit(void)
queue:nil
usingBlock:^(NSNotification *note) {
GCController *controller = note.object;
SDL_JoystickDeviceItem *device = deviceList;
while (device != NULL) {
SDL_JoystickDeviceItem *device;
SDL_LockJoysticks();
for (device = deviceList; device != NULL; device = device->next) {
if (device->controller == controller) {
IOS_RemoveJoystickDevice(device);
break;
}
device = device->next;
}
SDL_UnlockJoysticks();
}];
#endif /* SDL_JOYSTICK_MFI */
}