New Orientation Crash in iOS 6 beta 4

Forums Programming cocos2d support (graphics engine) New Orientation Crash in iOS 6 beta 4

This topic contains 22 replies, has 14 voices, and was last updated by  badben 1 year, 2 months ago.

Viewing 23 posts - 1 through 23 (of 23 total)
Author Posts
Author Posts
August 7, 2012 at 4:10 pm #243396

PDiTO
Participant
@pdito

Hi guys,

Getting a crash when testing on the new iOS 6 beta 4.

Error message is as follows:-

*** Terminating app due to uncaught exception ‘UIApplicationInvalidInterfaceOrientation’, reason: ‘Supported orientations has no common orientation with the application, and shouldAutorotate is returning YES’

Using cocos2d v1, not really changed anything from default in the rotation settings. Also note using kGameAutorotationUIViewController as rotation type.

Any suggestions how to fix? I’ve noticed if I click to allow portrait orientation in xcode the crash doesn’t occur, but the app is landscape, so I don’t want to allow this orientation!

Thanks,

Paul.

August 8, 2012 at 1:38 am #384950

ybian
@ybian

I’m having the same problem and I have nailed down the problem to GameCenter views (and I use DDGameKitHelper for GC integration), but I’ve not found the solution yet. I will reply here if I get it resolved.

August 8, 2012 at 6:19 am #384951

PDiTO
Participant
@pdito

Hi ybian,

That would be great thanks. Actually, it’s interesting, when I set portrait to an allowed orientation…game center does pop up on launch which is unusual. I will look at my implementation with that too. Note:I am not using DDHelper.

August 30, 2012 at 3:48 am #384952

ybian
@ybian

@PDiTO to update on this issue: you should have known that this is an iOS6 change as I see you participated in this thread: http://www.cocos2d-iphone.org/forum/topic/37742 I resolved my problem by the following steps:

1. check all orientations as allowed in my project summary panel

2. subclass UINavigationController:

@interface MyRootViewController : UINavigationController

@end


@implementation MyRootViewController

-(NSUInteger)supportedInterfaceOrientations{
return UIInterfaceOrientationMaskLandscape;
}

- (BOOL)shouldAutorotate {
return YES;
}

@end

3. change the root view controller to my own:

In - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions, change

// Create a Navigation Controller with the Director
navController_ = [[UINavigationController alloc] initWithRootViewController:director_]

to

// Create a Navigation Controller with the Director
navController_ = [[MyRootViewController alloc] initWithRootViewController:director_];

This works for me.

August 30, 2012 at 7:15 am #384953

PDiTO
Participant
@pdito

Thanks @ybian, appreciate the advice.

September 14, 2012 at 11:03 pm #384954

getbirdy
Participant
@getbirdy

That fix is for cocos2d 2.0 right? has anyone fixed the width/height reversal in the cocos2d 1.1 beta after setting the rootviewcontroller?

cocos2d 1.1 sets it up like this not sure what to change to fix the problem:

CCDirector *director = [CCDirector sharedDirector];

// Init the View Controller
viewController = [[RootViewController alloc] initWithNibName:nil bundle:nil];
viewController.wantsFullScreenLayout = YES;

EAGLView *glView = [EAGLView viewWithFrame:[window bounds]
pixelFormat:kEAGLColorFormatRGB565 // kEAGLColorFormatRGBA8
depthFormat:0 // GL_DEPTH_COMPONENT16_OES
];

// attach the openglView to the director
[director setOpenGLView:glView];

#if GAME_AUTOROTATION == kGameAutorotationUIViewController
[director setDeviceOrientation:kCCDeviceOrientationPortrait];
#else
[director setDeviceOrientation:kCCDeviceOrientationLandscapeLeft];
#endif

[viewController setView:glView];

// make the View Controller a child of the main window

[window addSubview: viewController.view];

Thank you!

September 14, 2012 at 11:25 pm #384955

stormple
@stormple

I was just wrestling with this. The apple developer forum had a fix that worked great across all devices and iOS versions. Here https://devforums.apple.com/thread/165384?tstart=0

Edit – At least ios 5 and 6

September 15, 2012 at 12:32 am #384956

getbirdy
Participant
@getbirdy

I’m still having the problem of the width and height being switched up even after that fix, I think its using setRootViewController that messes it up. Thanks for the link that is a good fix for the other problem

Edit: actually it looks like instead of mixing up height and width my game gets stuck in portrait mode now

September 15, 2012 at 2:38 am #384957

ajlondon
Participant
@ajlondon

This is what I did… and it seems to be working. I just submitted my App. It is in review. If anyone knows why this wouldn’t work, please tell…. I am using cocos2d 1.1beta.

In RootViewController.m put these two lines……

- (NSUInteger) supportedInterfaceOrientations { return UIInterfaceOrientationMaskLandscape;}

- (BOOL) shouldAutorotate { return YES;}

In your AppDelegate.m put

NSString *reqSysVer = @”6.0″;

NSString *currSysVer = [[UIDevice currentDevice] systemVersion];

if ([currSysVer compare:reqSysVer options:NSNumericSearch] !=NSOrderedAscending)

{ [window setRootViewController:viewController];}

else

{ [window addSubview: viewController.view]; }

And in the supported orientations in the summary screen I pressed all four grey buttons – Portrait, Upside Down, Landscape Left, Landscape Right, for both the iPad and iPhone.

I have a universal app that runs only in Landscape

It seems to be working fine. I tested it for a while, and came up with no problems using ios 5.0 and up on all devices.

September 15, 2012 at 8:03 pm #384958

getbirdy
Participant
@getbirdy

Got mine to work, it is very similar to yours ajlondon. The problem was i had to change to #define GAME_AUTOROTATION kGameAutorotationUIViewController under the gameconfig.h instead of letting CCDirector do it.

September 15, 2012 at 9:58 pm #384959

Dragyn
Moderator
@dragyn

I’m using cocos2D 1.01 on a project I’m updating, and I have MOST of the orientation issues solved under iOS6, but I still have one issue. The app is universal, and supports 3 types of rotation, depending on the scene and device:

1) Portrait & Portrait Upside Down (iPad)

2) Portrait Only (iPhone)

3) LandscapeLeft and LandscapeRight (iPad)

In the RootViewController.m, I have these new methods:

- (BOOL)shouldAutorotate
{
if (isLive == YES) {
if ([[GHStateHandler sharedManager] gameMode] == kPadMulti) {
return YES;
} else if ([[GHStateHandler sharedManager] gameMode] == kPadSingle) {
return YES;
}
}
return NO;
}

- (NSUInteger)supportedInterfaceOrientations
{
if (isLive == YES) {
if ([[GHStateHandler sharedManager] gameMode] == kPadMulti) {
return UIInterfaceOrientationMaskLandscapeLeft|UIInterfaceOrientationMaskLandscapeRight;
}
else if ([[GHStateHandler sharedManager] gameMode] == kPadSingle) {
return UIInterfaceOrientationMaskPortrait|UIInterfaceOrientationMaskPortraitUpsideDown;
}
else {
return UIInterfaceOrientationMaskPortrait;
}
}
else {
return UIInterfaceOrientationMaskPortrait;
}
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationLandscapeLeft;
}

This works for everything EXCEPT when I am moving from a Portrait scene to a Landscape scene. It starts by drawing the scene that should be in landscape in portrait (half off the screen), but when I rotate the device, everything goes back to the way I want (it will only rotate to a landscape orientation) and things look fine.

Previously, I was forcing the rotation to Landscape by putting in this call in my scene class:

[[CCDirector sharedDirector] setDeviceOrientation:kCCDeviceOrientationLandscapeLeft];

But now, when I do that, it works to begin with, but when I rotate, it looks “chopped” with the landscape image in a portrait view (half off the screen). It appears that forcing the orientation is not being communicated to the autorotation system, so it doesn’t “know” that I changed it, and it clobbers the scene with a bad transform.

Any ideas on how I can sort this one out? I’ve been trying all manner of things, and nothing seems to correct for it.

September 16, 2012 at 1:13 am #384960

getbirdy
Participant
@getbirdy

What do you have defined for game_autorotation under GameConfig.h?

September 16, 2012 at 1:17 am #384961

Dragyn
Moderator
@dragyn

My game_autorotation section was nuked because of the special needs of this project. All rotation is handled by these methods only. (Under prior versions, the jist of the code under “supportedInterfaceOrientations” that I posted was under the “shouldAutorotate…” method that we used prior to iOS6.)

September 16, 2012 at 3:09 am #384962

getbirdy
Participant
@getbirdy

So it looks fine in portrait until you rotate it and then it draws the landscape scene while in portrait before rotating to landscape?

September 16, 2012 at 3:18 am #384963

Dragyn
Moderator
@dragyn

I think I’ve resolved the issue. I am using the CCDirector line to “force” landscape mode, and in the supportInterfaceOrientations, I changed the line:

return UIInterfaceOrientationMaskLandscapeLeft|UIInterfaceOrientationMaskLandscapeRight;

to

return UIInterfaceOrientationMaskPortrait|UIInterfaceOrientationMaskPortraitUpsideDown;

So the rotation is technically happening on Portrait and PortraitUpsidedown, but it does allow the UI to be both landscape directions (which Apple requires for iPad apps), because I have forced the orientation to be 90 degrees off what it thinks it is doing. Everything appears to be functioning correctly now. I just submitted the update, so hopefully it passes review.

September 16, 2012 at 4:16 am #384964

tbone28
Participant
@tbone28

Verify that your info.plist also is saying the correct orientations you want to support.

October 25, 2012 at 8:41 pm #384965

williampower
@williampower

I have a landscape-only game. Cocos2d v1.

I did this:

Create a manager class for authentication. Have it return a BOOL indicating whether it is showing the auth popover in iOS 6. Set the BOOL to YES before showing the popover, set it to NO in the auth handler for the proper async conditions such as localPlayer.authenticated is true, auth has an error indicating auth stopped with anything but ‘auth in progress’.

In the App Delegate, implement application:supportedInterfaceOrientationsForWindow:, which is only called when you’re on iOS 6 or later. Check whether your manager class is showing the popover. If it is, return UIInterfaceOrientationMaskAll, otherwise return (for me with my landscape-only game) UIInterfaceOrientationMaskLandscape.


//APP DELEGATE STUFF
if ([GameCenterManager sharedManager].isShowingPopover) {
NSLog(@"showing popover");
return UIInterfaceOrientationMaskAll;
}else{
NSLog(@"NOT SHOWING POPOVER");
return UIInterfaceOrientationMaskLandscape;
}

//IN THE MANAGER CLASS'S AUTH CALL (targeted for iOS 6. you need to handle the prior iOS versions differently)
localPlayer.authenticateHandler = ^(UIViewController *viewController, NSError *error){
if (viewController != nil) {
// SET TO 'SHOWING' HERE
_isShowingPopover = YES;
[hostViewController presentViewController:viewController animated:NO completion:nil];
}
if (error) {
switch ([error code]) {
case GKErrorAuthenticationInProgress:
//DO NOTHING
break;
case GKErrorCancelled:
//USER HIT CANCEL BUTTON
_isShowingPopover = NO;
break;
default:
//SOME OTHER FAIL CONDITION. YOU MAY NEED MORE CODE TO HANDLE OTHER CASES. I HAVEN'T FINISHED TESTING ALL THE CASES YET.
_isShowingPopover = NO;
break;
}
}else if( localPlayer.authenticated ){
//SET TO 'NOT SHOWING'
_isShowingPopover = NO;
}else{
NSLog(@"no auth?");
//AUTH IS IN PROGRESS WHEN THIS GETS HIT. TEST THIS MORE THOROUGHLY 'JUST IN CASE'
}
};

October 31, 2012 at 12:28 pm #384966

razvan_b
Participant
@razvan_b

Thank’s so much @williampower.

You are a life saver. I adapted the code you posted and it made my app much stable on IOS6, also gave me the basic idea on how to solve related bugs and the one in which an achievement in my game that required to rotate the device did not work on IOS6!

here is one IOU as a sign of gratitude.

my code:

- (NSUInteger) application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
if(m_gc != nil)
{
if (m_gc->_isShowingPopover) {
NSLog(@"showing popover");
return UIInterfaceOrientationMaskAll;
}else{
NSLog(@"NOT SHOWING POPOVER");
return UIInterfaceOrientationMaskLandscape;
}
}
return UIInterfaceOrientationMaskLandscape;
}

November 11, 2012 at 8:16 am #384967

zszen
@zszen

http://www.cocos2d-iphone.org/forum/topic/36639#post-178154

nice work

December 12, 2012 at 4:14 am #384968

staticfiction
Participant
@staticfiction

Thanks @ybian. great solution.

December 21, 2012 at 8:28 am #384969

firestoke
Participant
@firestoke

hi guys,

I met the exactly same problem too. I found the root cause of this problem is:

When a user who doesn’t login game center account try to open my app in his iOS 6.0 device, it will popup a default game center login view with portrait display mode. But the orientation setting of my app only allows Landscape Left/Right display mode. So…….. it crashes!!!

So, if you follow ybian’s step 1 to turn on all orientations in project summary setting. Then app won’t crash at beginning any more, instead, it will show up a game center login dialog. But, in general situation, you shouldn’t turn on all orientation settings, or the display will be wrong in portrait mode.

If user have already login game center before launching app, then this problem won’t happen. So, I won’t do anything to fix this bug right now. Because this is a obviously internal bug in game center mechanism.

That’s all.

December 21, 2012 at 9:04 am #384970

cybergreg
Participant
@cybergreg

Copied from the Apple Dev forum:

funnest wrote:

Developers,

Landscape-only applications that invoke a portrait-only view controller (such as the Game Center sign-in screen or the UIImagePickerController) and are built using the iOS 6 SDK may crash with this error:

*** Terminating app due to uncaught exception ‘UIApplicationInvalidInterfaceOrientation’, reason: ‘Supported orientations has no common orientation with the application, and shouldAutorotate is returning YES’

As a workaround, landscape-only apps built using the iOS 6 SDK should implement the UIApplication delegate method -application:supportedInterfaceOrientationsForWindow: and ensure that portrait orientation (or any orientation mask which includes portrait orientation) is among the returned mask values. For example,

@implementation AppDelegate

-(NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window

{

if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)

return UIInterfaceOrientationMaskAll;

else /* iphone */

return UIInterfaceOrientationMaskAllButUpsideDown;

}

Note that landscape-only apps should continue to specify landscape-only orientations in their info.plist (and/or the Summary pane of their Target settings in Xcode). Doing so will ensure the app is initially launched in the correct orientation.

Subsequently, view controllers in your app can override the -supportedInterfaceOrientations: method to limit the orientations they support. The intersection of the app’s orientation mask (returned by -application:supportedInterfaceOrientationsForWindow:) and a view controller’s orientation mask (returned by -supportedInterfaceOrientations:) is used to determine which orientations a view controller can be rotated into. For example:

@implementation SampleLandscapeViewController

-(NSUInteger)supportedInterfaceOrientations

{

return UIInterfaceOrientationMaskLandscape;

}

Note, if the app uses a container view controller (such as UINavigationController) and requires pre-iOS 6 autorotation behavior, the implementation of -supportedInterfaceOrientations: should return the supported orientations of the appropriate child view controller. With a UINavigationController this would typically be the topViewController.

For more information about managing interface orientation see the UIApplication Delegate reference, UIViewController reference, and View Controller Programming Guide for iOS.

End of quote

iOS6 changed a lot with respect to both UIViews and UIViewControllers rotation, it’s not something you should view as a bug, esp since nothing has changed in iOS6.1

January 30, 2013 at 12:15 pm #384971

badben
Participant
@badben

Hello,

I got this crash when I tap on the Continue Button on the AdColony video with iOS 6 only.

My app is designed for the portrait orientation.

I fixed the problem by adding a supported orientation: Landscape Left.

Viewing 23 posts - 1 through 23 (of 23 total)

You must be logged in to reply to this topic.