Search Issue Tracker

Status: Active

Votes

156

Found in

5.4.0f3

Issue ID

835745

Regression

No

[iOS] Changing the screen orientation via a script sometimes results in corrupted view on iOS 10

iOS

-

-

Priority: 3Not yet prioritized for a release

-

Severity: 2No workaround

When the orientation of the screen is changed via a script (with Screen.orientation) on iOS 10 devices, sometimes the screen remains in portrait orientation, but the game view gets flipped and goes over the edge of the screen and leaves black area in the bottom part of the screen.

Steps to reproduce:
1) Open the attached project.
2) Build 'MainScene' for iOS.
3) Run on an iOS 10 device.
4) Press the 'Switch to landscape' UI button.

If the button is clicked 2-3 seconds after launch - the rotation should fail - black area appears at the bottom of the screen, half of the game view is not visible. If it does not, quit the app completely, re-launch it and repeat step 5). This occurs with both Metal and OpenGLES on iOS 10.

Reproduced on:
5.5.0b5, 5.4.1p3, 5.3.6p6

Devices:
iPhone 7 iOS 10 - reproduced
iPhone 7 iOS 10.1 - reproduced
iPhone 7 Plus iOS 10.0.2 - reproduced
iPhone 5 iOS 10 - not reproduced
iPad Mini 2 iOS 10 - not reproduced
iPhone 5S iOS 9.2.1 - not reproduced
It should also be reproducible on iPhone 6.

Comments (52)

  1. 85916f2e42ab5a983e1943f37437c764?d=mm

    DarkMagicCK

    Dec 12, 2016 13:31

    Though, this causes wired auto rotation for our users when they bring our game front Background to Front, That's wired, and I dont know if Apple will reject our app because it behaves strange, just like a bug.

    Hope this bug would be fixed soon.

  2. 85916f2e42ab5a983e1943f37437c764?d=mm

    DarkMagicCK

    Dec 12, 2016 13:26

    Thanks to FSPARK's workaround, but the code will till crash our app.
    After digging in our game, I found the app only crashes in this situation:
    (Our game only supports landscape left and right)

    1. Open your game
    2. Get in any scenes which is somewhat complex.(Very simple scenes does not crash in our game)
    3. Lock your iphone.
    4. After ApplicationDidEnterBackground, unlock your iPhone with portrait orientation;
    5. Game crash.

    And with FSPARK's code, the app still crash when you set the device orientation to the same when you lock your iPhone. The screen do not auto rotate to wakeup Unity.

    So we changed the code a little, to always rotate the app to the opposite landscape, and the app does not crash any more. Here's the code:

    UIInterfaceOrientation interfaceOrientation = [[UIApplication sharedApplication] statusBarOrientation];
    NSNumber *value = [NSNumber numberWithInt:UIDeviceOrientationLandscapeRight];

    if(interfaceOrientation == UIInterfaceOrientationLandscapeLeft){
    value = [NSNumber numberWithInt:UIDeviceOrientationLandscapeLeft];
    }else if(interfaceOrientation == UIInterfaceOrientationLandscapeRight){
    value = [NSNumber numberWithInt:UIDeviceOrientationLandscapeRight];
    }

    [[UIDevice currentDevice] setValue:value forKey:@"orientation"];

  3. 13db2970a528603271106a85e6e5a55f?d=mm

    ptblk

    Dec 08, 2016 20:33

    if you dont vote for it, it wont be fixed. Just commenting here doesnt help

  4. 791c3824aa0b2c240b3e20b0c7bdaad3?d=mm

    Ethan_VisualVocal

    Dec 08, 2016 17:40

    Unfortunately, we just got our first submission rejected by Apple over this.

    Since this issue has been around since iOS 10 shipped, I guess we will have to try FSpark's workaround!

  5. 5ba75621e96f1b44463991d93a933fe6?d=mm

    Mohammad-Faisal-Aleem

    Dec 06, 2016 15:40

    Voted.

  6. D4b5154ffde92a67902bc4e8bc08a7f6?d=mm

    dttson91

    Dec 06, 2016 14:11

    Everyone please vote, don't just comments, there are only 9 votes left to raised this issue to Unity

  7. 5ba75621e96f1b44463991d93a933fe6?d=mm

    Mohammad-Faisal-Aleem

    Dec 05, 2016 22:36

    Does anybody have found a proper fix for it. Have unity fixed this issue in some version above 5.4.x series? I am also stuck in this. It should have been answered or handled till now.

  8. 4b38dae05c4e294ee8362ec988231815?d=mm

    matbou

    Dec 01, 2016 11:27

    Got the same issue using Unity 5.4.2f2.
    It's a really severe issue for us. Please fix.

  9. 354e882a407bfcd2ebb89e43d26c5c63?d=mm

    FSpark

    Nov 30, 2016 17:56

    In case this helps anyone - I raised a similar issue where the iOS device (iOS 10) the UI appeared locked and display distorted on resuming app after extended sleep (see https://fogbugz.unity3d.com/default.asp?846895_82ts9nnt8gm5rp25 ).

    The quick workaround I used was to modify the Unity generated UnityAppController.mm:

    - (void)applicationWillEnterForeground:(UIApplication*)application
    {
    ::printf("-> applicationWillEnterForeground()\n");

    // applicationWillEnterForeground: might sometimes arrive *before* actually initing unity (e.g. locking on startup)
    if(_unityAppReady)
    {
    // if we were showing video before going to background - the view size may be changed while we are in background
    [GetAppController().unityView recreateGLESSurfaceIfNeeded];
    }


    //
    // Bug workaround:
    // On returning from device sleep mode, Unity UI is lock and will not respond
    // If the device is rotated, Unity will 'wake up'
    // So force landscape orientation to wake up Unity
    //
    [[UIDevice currentDevice] orientation];
    NSNumber *value = [NSNumber numberWithInt:UIInterfaceOrientationPortrait];
    switch( [[UIDevice currentDevice] orientation] )
    {
    case UIDeviceOrientationPortrait:
    value = [NSNumber numberWithInt:UIInterfaceOrientationPortrait];
    break;


    case UIDeviceOrientationPortraitUpsideDown:
    value = [NSNumber numberWithInt:UIInterfaceOrientationPortraitUpsideDown];
    break;
    case UIDeviceOrientationLandscapeLeft:
    value = [NSNumber numberWithInt:UIInterfaceOrientationLandscapeLeft];
    break;


    case UIDeviceOrientationLandscapeRight:
    value = [NSNumber numberWithInt:UIInterfaceOrientationLandscapeRight];
    break;
    default:
    // setting to portrait does not work
    // value = [NSNumber numberWithInt:UIInterfaceOrientationPortrait];
    // but forcing the device into landscape mode and then allow it to auto-correct works
    value = [NSNumber numberWithInt:UIInterfaceOrientationLandscapeLeft];
    break;
    };
    [[UIDevice currentDevice] setValue:value forKey:@"orientation"];
    }

  10. 3e1043a130b785a00a76bf2538600b31?d=mm

    jimmyzhao

    Nov 30, 2016 08:42

    Reproduced this issue in iphon5s, iphone6, etc. with Unity 5.3.4f1

    pls fix..

All about bugs

View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.