Skip to content

Commit

Permalink
Fixed building on iOS with MFI controllers disabled
Browse files Browse the repository at this point in the history
  • Loading branch information
slouken committed May 27, 2020
1 parent 97ca96b commit e9f567c
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/joystick/iphoneos/SDL_sysjoystick.m
Expand Up @@ -393,8 +393,6 @@ @interface GCMicroGamepad (SDL)
IOS_JoystickInit(void)
{
@autoreleasepool {
NSNotificationCenter *center = [NSNotificationCenter defaultCenter];

#if !TARGET_OS_TV
if (SDL_GetHintBoolean(SDL_HINT_ACCELEROMETER_AS_JOYSTICK, SDL_TRUE)) {
/* Default behavior, accelerometer as joystick */
Expand All @@ -417,6 +415,8 @@ @interface GCMicroGamepad (SDL)
SDL_AppleTVRemoteRotationHintChanged, NULL);
#endif /* TARGET_OS_TV */

NSNotificationCenter *center = [NSNotificationCenter defaultCenter];

connectObserver = [center addObserverForName:GCControllerDidConnectNotification
object:nil
queue:nil
Expand Down Expand Up @@ -466,17 +466,24 @@ @interface GCMicroGamepad (SDL)
static int
IOS_JoystickGetDevicePlayerIndex(int device_index)
{
#ifdef SDL_JOYSTICK_MFI
SDL_JoystickDeviceItem *device = GetDeviceForIndex(device_index);
return device ? (int)device->controller.playerIndex : -1;
if (device && device->controller) {
return (int)device->controller.playerIndex;
}
#endif
return -1;
}

static void
IOS_JoystickSetDevicePlayerIndex(int device_index, int player_index)
{
#ifdef SDL_JOYSTICK_MFI
SDL_JoystickDeviceItem *device = GetDeviceForIndex(device_index);
if (device) {
if (device && device->controller) {
device->controller.playerIndex = player_index;
}
#endif
}

static SDL_JoystickGUID
Expand Down

0 comments on commit e9f567c

Please sign in to comment.