Fixed a crash on iOS when none of the orientations in Info.plist match the SDL window's actual orientation.
authorAlex Szpakowski <slime73@gmail.com>
Tue, 05 May 2015 16:16:10 -0300
changeset 9584fceb5503cadf
parent 9583 0bd764eb2b99
child 9585 8339700453c6
Fixed a crash on iOS when none of the orientations in Info.plist match the SDL window's actual orientation.

Fixes bug #2967.
Xcode-iOS/SDL/SDL.xcodeproj/project.pbxproj
src/video/uikit/SDL_uikitwindow.m
     1.1 --- a/Xcode-iOS/SDL/SDL.xcodeproj/project.pbxproj	Mon May 04 21:47:40 2015 -0700
     1.2 +++ b/Xcode-iOS/SDL/SDL.xcodeproj/project.pbxproj	Tue May 05 16:16:10 2015 -0300
     1.3 @@ -1082,7 +1082,7 @@
     1.4  		29B97313FDCFA39411CA2CEA /* Project object */ = {
     1.5  			isa = PBXProject;
     1.6  			attributes = {
     1.7 -				LastUpgradeCheck = 0420;
     1.8 +				LastUpgradeCheck = 0630;
     1.9  			};
    1.10  			buildConfigurationList = C01FCF4E08A954540054247B /* Build configuration list for PBXProject "SDL" */;
    1.11  			compatibilityVersion = "Xcode 3.2";
    1.12 @@ -1253,7 +1253,8 @@
    1.13  				GCC_OPTIMIZATION_LEVEL = 0;
    1.14  				GCC_SYMBOLS_PRIVATE_EXTERN = YES;
    1.15  				GCC_WARN_ABOUT_RETURN_TYPE = YES;
    1.16 -				IPHONEOS_DEPLOYMENT_TARGET = 3.1.3;
    1.17 +				IPHONEOS_DEPLOYMENT_TARGET = 5.1.1;
    1.18 +				ONLY_ACTIVE_ARCH = YES;
    1.19  				SDKROOT = iphoneos;
    1.20  				TARGETED_DEVICE_FAMILY = "1,2";
    1.21  			};
    1.22 @@ -1265,7 +1266,7 @@
    1.23  				"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
    1.24  				GCC_SYMBOLS_PRIVATE_EXTERN = YES;
    1.25  				GCC_WARN_ABOUT_RETURN_TYPE = YES;
    1.26 -				IPHONEOS_DEPLOYMENT_TARGET = 3.1.3;
    1.27 +				IPHONEOS_DEPLOYMENT_TARGET = 5.1.1;
    1.28  				SDKROOT = iphoneos;
    1.29  				TARGETED_DEVICE_FAMILY = "1,2";
    1.30  			};
    1.31 @@ -1278,10 +1279,10 @@
    1.32  				CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
    1.33  				CLANG_WARN_OBJC_IMPLICIT_ATOMIC_PROPERTIES = YES;
    1.34  				COPY_PHASE_STRIP = NO;
    1.35 -				IPHONEOS_DEPLOYMENT_TARGET = 5.1.1;
    1.36  				GCC_WARN_MULTIPLE_DEFINITION_TYPES_FOR_SELECTOR = YES;
    1.37  				GCC_WARN_STRICT_SELECTOR_MATCH = YES;
    1.38  				GCC_WARN_UNDECLARED_SELECTOR = YES;
    1.39 +				IPHONEOS_DEPLOYMENT_TARGET = 5.1.1;
    1.40  				PRODUCT_NAME = SDL2;
    1.41  				SKIP_INSTALL = YES;
    1.42  			};
    1.43 @@ -1294,10 +1295,10 @@
    1.44  				CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
    1.45  				CLANG_WARN_OBJC_IMPLICIT_ATOMIC_PROPERTIES = YES;
    1.46  				COPY_PHASE_STRIP = YES;
    1.47 -				IPHONEOS_DEPLOYMENT_TARGET = 5.1.1;
    1.48  				GCC_WARN_MULTIPLE_DEFINITION_TYPES_FOR_SELECTOR = YES;
    1.49  				GCC_WARN_STRICT_SELECTOR_MATCH = YES;
    1.50  				GCC_WARN_UNDECLARED_SELECTOR = YES;
    1.51 +				IPHONEOS_DEPLOYMENT_TARGET = 5.1.1;
    1.52  				PRODUCT_NAME = SDL2;
    1.53  				SKIP_INSTALL = YES;
    1.54  			};
     2.1 --- a/src/video/uikit/SDL_uikitwindow.m	Mon May 04 21:47:40 2015 -0700
     2.2 +++ b/src/video/uikit/SDL_uikitwindow.m	Tue May 05 16:16:10 2015 -0300
     2.3 @@ -191,13 +191,10 @@
     2.4          }
     2.5  
     2.6          if (data.uiscreen == [UIScreen mainScreen]) {
     2.7 -            NSUInteger orientations = UIKit_GetSupportedOrientations(window);
     2.8 -            UIApplication *app = [UIApplication sharedApplication];
     2.9 -
    2.10              if (window->flags & (SDL_WINDOW_FULLSCREEN|SDL_WINDOW_BORDERLESS)) {
    2.11 -                app.statusBarHidden = YES;
    2.12 +                [UIApplication sharedApplication].statusBarHidden = YES;
    2.13              } else {
    2.14 -                app.statusBarHidden = NO;
    2.15 +                [UIApplication sharedApplication].statusBarHidden = NO;
    2.16              }
    2.17          }
    2.18  
    2.19 @@ -345,9 +342,21 @@
    2.20  UIKit_GetSupportedOrientations(SDL_Window * window)
    2.21  {
    2.22      const char *hint = SDL_GetHint(SDL_HINT_ORIENTATIONS);
    2.23 +    NSUInteger validOrientations = UIInterfaceOrientationMaskAll;
    2.24      NSUInteger orientationMask = 0;
    2.25  
    2.26      @autoreleasepool {
    2.27 +        SDL_WindowData *data = (__bridge SDL_WindowData *) window->driverdata;
    2.28 +        UIApplication *app = [UIApplication sharedApplication];
    2.29 +
    2.30 +        /* Get all possible valid orientations. If the app delegate doesn't tell
    2.31 +         * us, we get the orientations from Info.plist via UIApplication. */
    2.32 +        if ([app.delegate respondsToSelector:@selector(application:supportedInterfaceOrientationsForWindow:)]) {
    2.33 +            validOrientations = [app.delegate application:app supportedInterfaceOrientationsForWindow:data.uiwindow];
    2.34 +        } else if ([app respondsToSelector:@selector(supportedInterfaceOrientationsForWindow:)]) {
    2.35 +            validOrientations = [app supportedInterfaceOrientationsForWindow:data.uiwindow];
    2.36 +        }
    2.37 +
    2.38          if (hint != NULL) {
    2.39              NSArray *orientations = [@(hint) componentsSeparatedByString:@" "];
    2.40  
    2.41 @@ -379,10 +388,17 @@
    2.42              }
    2.43          }
    2.44  
    2.45 -        /* Don't allow upside-down orientation on the phone, so answering calls is in the natural orientation */
    2.46 +        /* Don't allow upside-down orientation on phones, so answering calls is in the natural orientation */
    2.47          if ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPhone) {
    2.48              orientationMask &= ~UIInterfaceOrientationMaskPortraitUpsideDown;
    2.49          }
    2.50 +
    2.51 +        /* If none of the specified orientations are actually supported by the
    2.52 +         * app, we'll revert to what the app supports. An exception would be
    2.53 +         * thrown by the system otherwise. */
    2.54 +        if ((validOrientations & orientationMask) == 0) {
    2.55 +            orientationMask = validOrientations;
    2.56 +        }
    2.57      }
    2.58  
    2.59      return orientationMask;