UnityDefaultViewController should be used only if unity is set to autorotate

Hi,

I have this crash on iOS 8.2 (iPhone6 plus) when I build my roject (and Unity is set to “Auto Rotation”…):

Somebody can help me ?
Thank you very much.
Best regards,
AB

Could you please submit a bug and attach a small reproduction project to it? Thank you

Hi,

I’m sorry but I solved it yet : I just changed the orientation setting in the build setting.

Sorry

I’m also experiencing this problem. The project is set to build with Auto Rotate as the desired orientation. The main menu selection screen will operate in either orientation. However, since this project is a set of mini-games, some designed for portrait and some for landscape, periodically the orientation will change and lock. If I’m in portrait, load one of the games that’s landscape, and then rotate the device while the game is loading, I get the same crash as above.

It’s being caused by line 102 of the UnityViewControllerBase.mm file, in which it performs an assert to check for auto rotation. If I comment out this line in the Xcode project, the app works as expected, so it seems this assert is not behaving as intended. Is there a way to keep this line commented out as part of the build process, or is there another setting I can use to prevent the assert from failing? It is a requirement of these games that we be able to prevent auto-rotation at some times but not others.

If I’m in portrait, load one of the games that’s landscape, and then rotate the device while the game is loading, I get the same crash as above.
that’s kinda interesting - it should actually switch directly, bypassing “auto-rotating” view controller.
can you bug report with small repro? (we dont need your mini-games, just setup - so empty scenes with orientation logic would suffice).
And yes, i would say that if you tested, commenting assert should be more or less fine

Sure thing, Alexey, I can file a bug report. In the mean time, is there a way to automate commenting of that assert so that it’s part of the build process? We’re using UCB for most of our builds so we can’t really manually remove it each time.

I found a good post-process example out there from one of the UCB guys and modified it to suit my needs. Posting it here in case it’s helpful to someone with this specific problem.

2154490–142271–PostBuildProcessor.cs (1.3 KB)

4 Likes

FYI you want to drop that script in an Editor folder somewhere in the project.

Thank you for this - just lost a day to this issue in a live app. Here’s hoping I can get Apple to expedite the review of the fixed version!

You deserve a medal! Had exactly the same problem (for the same reason, multiple mini-games :P). Also needed things to work with Cloud Build, so your automatic commenting script is perfect! So rare to come across a solution like this where someone has also gone to the effort of writing (AND SHARING) their fix like this. So rare that this is my first post here after so many years of lurking for solutions :wink:

Cheers!

I have same problem, but PostBuildProcessor is not working :frowning: Do you have any suggestion?

@Alexey Here is code:

void Awake() {

Screen.autorotateToLandscapeLeft = false;
Screen.autorotateToLandscapeRight = false;
Screen.autorotateToPortrait = false;
Screen.autorotateToPortraitUpsideDown = false;

if( Screen.orientation != ScreenOrientation.LandscapeLeft ) {
Screen.orientation = ScreenOrientation.LandscapeLeft;
}

}

I found that it is working in Start()

Hey any solutions?
I am in the same issue :frowning:

I think I am also experiencing the same problem, here is an excerpt from crash report:

Version: 1 (1.8)
Code Type: ARM-64 (Native)
Parent Process: launchd [1]

Date/Time: 2016-03-25 13:20:33.33 -0700
Launch Time: 2016-03-25 13:20:32.32 -0700
OS Version: iOS 9.3 (13E233)
Report Version: 105

Exception Type: EXC_CRASH (SIGABRT)
Exception Codes: 0x0000000000000000, 0x0000000000000000
Exception Note: EXC_CORPSE_NOTIFY
Triggered by Thread: 0

Filtered syslog:
None found

Last Exception Backtrace:
0 CoreFoundation 0x18177ae38 0x181650000 + 1224248
1 libobjc.A.dylib 0x180ddff80 0x180dd8000 + 32640
2 CoreFoundation 0x18177ad08 0x181650000 + 1223944
3 Foundation 0x182100124 0x18205c000 + 672036
4 MyApplicationName 0x1000316c0 -[UnityDefaultViewController supportedInterfaceOrientations] (UnityViewControllerBaseiOS.mm:107)
5 UIKit 0x186935a20 0x1868a8000 + 580128
6 UIKit 0x18693f150 0x1868a8000 + 618832
7 UIKit 0x18693f0c8 0x1868a8000 + 618696
8 UIKit 0x18693dbb0 0x1868a8000 + 613296
9 UIKit 0x1868b7910 0x1868a8000 + 63760
10 UIKit 0x1868b6c40 0x1868a8000 + 60480
11 Foundation 0x1820acd50 0x18205c000 + 331088
12 UIKit 0x1868b6ac4 0x1868a8000 + 60100
13 UIKit 0x1868c4578 0x1868a8000 + 116088
14 MyApplicationName 0x10002fb5c -[UnityAppController(ViewHandling) showGameUI] (UnityAppController+ViewHandling.mm:169)
15 MyApplicationName 0x10002c2d8 -[UnityAppController startUnity:] (UnityAppController.mm:117)
16 Foundation 0x182142628 0x18205c000 + 943656
17 CoreFoundation 0x18173181c 0x181650000 + 923676
18 CoreFoundation 0x1817314c0 0x181650000 + 922816
19 CoreFoundation 0x18172ebd4 0x181650000 + 912340
20 CoreFoundation 0x181658d10 0x181650000 + 36112
21 GraphicsServices 0x182f40088 0x182f34000 + 49288
22 UIKit 0x186925f70 0x1868a8000 + 515952
23 MyApplicationName 0x1000199cc main (main.mm:32)
24 libdyld.dylib 0x1811f68b8 0x1811f4000 + 10424

Looking at UnityViewControllerBaseiOS.mm:107 :

NSAssert(UnityShouldAutorotate(), @“UnityDefaultViewController should be used only if unity is set to autorotate”);

But all builds succeeded on XCode :frowning: with just warnings related, from Classes/UI/UnityAppController+ViewHandling.mm:

Incompatible pointer types assigning to ‘UnityViewControllerBase *’ from ‘UIViewController *’

I need to change device orientation in my application at runtime, probably assigning Screen.Orientation to some values generate this crash.

Any solution? I don’t want to remove asserts from mm files.

Thanks!

I am using Unity 5.3.1f1, Xcode 7.2 (7C68)

I think is the same issue as: Possible auto rotation crash on iOS (Unity 5.2.3p3) - Unity Engine - Unity Discussions

Updated the post-process commenting script that KAKE shared – it fixes a few issues:

  • The filename containing the offending NSAssert changed in December 2015 with Unity 5.3.1 due to tvOS support being added – the script now handles Unity versions before and after this change.
  • Changed it to work with local builds instead of UCB.
  • Added a log warning if it failed to replace the string.
  • The post-process script would keep re-commenting the line if you Build → Appended. It no longer does this (but at the expense of a more fragile search string.)

Hope this helps someone else!

2614632–183421–PostBuildProcessCallback.cs (2.08 KB)

Hi,

It looks like following issue could be reproduced via following code:

// Current orientation is Landscape and we want to set it as Portrait:
Screen.orientation = ScreenOrientation.Portrait;

Screen.autorotateToLandscapeLeft = false;
Screen.autorotateToLandscapeRight = false;
Screen.autorotateToPortrait = true;
Screen.autorotateToPortraitUpsideDown = true;

This issue was fixed in the following way: before Autorotate configuration we should set Screen.orientation to Autorotate (but not Portrait or Landscape):

// Current orientation is Landscape and we want to set it as Portrait:
Screen.orientation = ScreenOrientation.AutoRotation;

Screen.autorotateToLandscapeLeft = false;
Screen.autorotateToLandscapeRight = false;
Screen.autorotateToPortrait = true;
Screen.autorotateToPortraitUpsideDown = true;

Hope it will help somebody :slight_smile:

3 Likes

We are also seeing this crash in our live game on Unity 5.4.4p3. We are not able to repro, but it is definitely happening to users. Is anyone from Unity looking into a fix for this?

[B]Name[/B]
NSInternalInconsistencyException

[B]Reason[/B]
UnityDefaultViewController should be used only if unity is set to autorotate

[B]App Version[/B] 0.2.1 (15218)
Download
Crashed Thread

0 CoreFoundation 0x0000000182c52db0 __exceptionPreprocess + 120
1    libobjc.A.dylib 0x00000001822b7f80 objc_exception_throw + 52
2    CoreFoundation 0x0000000182c52c80 +[NSException raise:format:arguments:] + 104
3    Foundation 0x00000001835d8154 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 108
!    4    possum 0x0000000100101c00 -[UnityDefaultViewController supportedInterfaceOrientations] (UnityViewControllerBaseiOS.mm:112)
5    UIKit 0x0000000187e21b38 -[UIViewController __supportedInterfaceOrientations] + 700
6    UIKit 0x000000018808b55c -[UIApplicationRotationFollowingController supportedInterfaceOrientations] + 104
7    UIKit 0x0000000187e21b38 -[UIViewController __supportedInterfaceOrientations] + 700
8    UIKit 0x0000000187e2b268 -[UIViewController __withSupportedInterfaceOrientation:apply:] + 48
9    UIKit 0x0000000187e2b1e0 -[UIViewController setInterfaceOrientation:] + 136
10    UIKit 0x0000000187e29cc8 -[UIViewController viewDidMoveToWindow:shouldAppearOrDisappear:] + 1156
11    UIKit 0x0000000187da3a10 -[UIView(Internal) _didMoveFromWindow:toWindow:] + 1368
12    UIKit 0x0000000187da2d40 __45-[UIView(Hierarchy) _postMovedFromSuperview:]_block_invoke + 148
13    UIKit 0x0000000187da2ba8 -[UIView(Hierarchy) _postMovedFromSuperview:] + 500
14    UIKit 0x0000000187db0678 -[UIView(Internal) _addSubview:positioned:relativeTo:] + 1780
15    UIKit 0x0000000187daf7e8 -[UIWindow addRootViewControllerViewIfPossible] + 660
16    UIKit 0x0000000187e2149c -[UIWindow setRootViewController:] + 1072
17    UIKit 0x0000000187e75340 -[UITextEffectsWindow(UIObjectsForPerScreen) _initWithScreen:options:] + 660
18    UIKit 0x0000000187e74f60 +[_UIObjectPerScreen objectOfClass:forScreen:withOptions:createIfNecessary:] + 656
19    UIKit 0x00000001882b17a4 +[UITextEffectsWindow _sharedTextEffectsWindowforScreen:aboveStatusBar:allowHosted:matchesStatusBarOrientationOnAccess:] + 568
20    UIKit 0x0000000187e74ca0 +[UITextEffectsWindow sharedTextEffectsWindowForScreen:] + 152
21    UIKit 0x0000000187e74bdc -[UIPeripheralHost(UIKitInternal) containerWindow] + 192
22    UIKit 0x000000018843e320 -[UIPeripheralHost(UIKitInternal) containerRootController] + 16
23    UIKit 0x0000000187e630d8 -[UIPeripheralHost isUndocked] + 16
24    UIKit 0x0000000187eac104 +[UIPeripheralHost(UIKitInternal) visiblePeripheralFrame] + 44
25    UIKit 0x00000001881eda7c -[_UIKeyboardLayoutAlignmentView _matchInitialKeyboardFrame] + 32
26    UIKit 0x00000001881eda38 -[_UIKeyboardLayoutAlignmentView didMoveToWindow] + 428
27    UIKit 0x0000000187da3ac8 -[UIView(Internal) _didMoveFromWindow:toWindow:] + 1552
28    UIKit 0x0000000187da2d40 __45-[UIView(Hierarchy) _postMovedFromSuperview:]_block_invoke + 148
29    Foundation 0x0000000183584cc0 -[NSISEngine withBehaviors:performModifications:] + 164
30    UIKit 0x0000000187da2bc4 -[UIView(Hierarchy) _postMovedFromSuperview:] + 528
31    UIKit 0x0000000187db0678 -[UIView(Internal) _addSubview:positioned:relativeTo:] + 1780
32    UIKit 0x0000000188208070 -[_UIAlertControllerPresentationController presentationTransitionWillBegin] + 144
33    UIKit 0x0000000188109fb0 __71-[UIPresentationController _initViewHierarchyForPresentationSuperview:]_block_invoke + 1636
34    UIKit 0x00000001881080c8 __56-[UIPresentationController runTransitionForCurrentState]_block_invoke + 328
35    UIKit 0x000000018805b0c8 _runAfterCACommitDeferredBlocks + 288
36    UIKit 0x0000000188068a80 _cleanUpAfterCAFlushAndRunDeferredBlocks + 88
37    UIKit 0x0000000187d9a5a4 _afterCACommitHandler + 92
38    CoreFoundation 0x0000000182c08728 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 28
39    CoreFoundation 0x0000000182c064cc __CFRunLoopDoObservers + 368
40    CoreFoundation 0x0000000182c068fc __CFRunLoopRun + 924
41    CoreFoundation 0x0000000182b30c50 CFRunLoopRunSpecific + 380
42    GraphicsServices 0x0000000184418088 GSEventRunModal + 176
43    UIKit 0x0000000187e12088 UIApplicationMain + 200
44    possum 0x00000001000d7510 main (main.mm:32)

If you build with the unity boot splash screen disabled try building with it enabled. I found this made a difference for me. The screen orientation setting stuff might need to be called outside of awake

Does it make sense to get this exception if I have the autorotation disabled?
My only view is portrait but im getting this crash.