Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

iOS crashes when changing screen orientation.

Discussion in 'iOS and tvOS' started by Calamity_Jones, Feb 8, 2021.

  1. Calamity_Jones

    Calamity_Jones

    Joined:
    Jul 31, 2019
    Posts:
    25
    We've been having issues on iOS when changing scene from menu to a game mode (we use portrait for the menu, and landscape for game modes). The app was crashing as soon as the scene finished loading - I had a script in each scene that changes the orientation. Interestingly, the app ONLY crashed on newer iOS devices (e.g. XS, XR, etc), and NEVER on the older iPhone 7 I use for testing.

    I recently changed the code to switch screen orientation before loading the new scene, and now the crashes seem to happen on the iPhone 7, and no longer on the newer devices.

    This is my code for fading out the previous scene, and loading in the new:

    Code (CSharp):
    1. private IEnumerator Scene_LoadNewFadeOut(string SceneToLoad)
    2.     {
    3.         Canvas_Fader.SetActive(true);
    4.         Image FadingImage = Canvas_Fader.GetComponentInChildren<Image>();
    5.         FadingImage.canvasRenderer.SetAlpha(0.0f);
    6.         FadingImage.CrossFadeAlpha(1.0f, 0.5f, false);
    7.         yield return new WaitForSeconds(0.5f);
    8.  
    9.         if (SceneToLoad == "MainMenu_Mobile")
    10.         {
    11.             Screen.orientation = ScreenOrientation.Portrait;
    12.         }
    13.         else
    14.         {
    15.             Screen.orientation = ScreenOrientation.LandscapeLeft;
    16.         }
    17.         yield return new WaitForSeconds(0.5f);
    18.  
    19.         UIManagerInGame.HidePanels();
    20.         CurrentScene = SceneToLoad;
    21.         AsyncOperation asyncLoad = SceneManager.LoadSceneAsync(CurrentScene);
    22.  
    23.         // Wait until the asynchronous scene fully loads
    24.         while (!asyncLoad.isDone)
    25.         {
    26.             yield return null;
    27.         }
    28.     }
    Once a scene loads, I fade back in with this (doubt it's relevant, but I'll include it):

    Code (CSharp):
    1.     private IEnumerator Scene_LoadNewFadeIn()
    2.     {
    3.         Image FadingImage = Canvas_Fader.GetComponentInChildren<Image>();
    4.         FadingImage.canvasRenderer.SetAlpha(1.0f);
    5.         FadingImage.CrossFadeAlpha(0.0f, 0.5f, false);
    6.         yield return new WaitForSeconds(0.5f);
    7.         Canvas_Fader.SetActive(false);
    8.     }
    I noticed that either the app crashes on the first attempt at going into a game (switching from portrait to landscape) - or when returning to the menu (landscape > portrait), or randomly runs in "magical stable mode" and works fine. I also got a completely black screen on one attempt - I guess it de-loaded the current scene and failed to load the next one?

    Finally, the crashes happen after the fade-out finishes, which leads me to suspect that the orientation change is causing the problem - the actual scene loading is delayed by a further 0.5s after the orientation change.

    Any ideas?
     
  2. Calamity_Jones

    Calamity_Jones

    Joined:
    Jul 31, 2019
    Posts:
    25
    I got two crash reports that report this as the problem:

    Native Crash - Unknown Function (/System/Library/Extensions/AppleMetalGLRenderer.bundle/AppleMetalGLRenderer)

    And crashed on thread 25:

    Thread 25 (crashed)
    0 AppleMetalGLRenderer 0x00000001c7798868 <system symbols missing>
    1 AppleMetalGLRenderer 0x00000001c779c908 <system symbols missing>
    2 AppleMetalGLRenderer 0x00000001c779fd68 <system symbols missing>
    3 GLEngine 0x00000001b1c1e494 <system symbols missing>
    4 UnityFramework 0x0000000103b168f4 ApiGLES::Clear(unsigned int, ColorRGBAf const&, bool, float, int)
    5 UnityFramework 0x0000000103afa65c GfxDeviceWorker::RunCommand(ThreadedStreamBuffer&)
    6 UnityFramework 0x0000000103afb740 GfxDeviceWorker::RunExt(ThreadedStreamBuffer&)
    7 UnityFramework 0x0000000103af2908 GfxDeviceWorker::RunGfxDeviceWorker(void*)
    8 UnityFramework 0x0000000103d52d44 Thread::RunThreadWrapper(void*)
    9 libsystem_pthread.dylib 0x00000001c72a6b70 <system symbols missing>
    10 libsystem_pthread.dylib 0x00000001c72ab880 <system symbols missing>

    I uploaded a symbols file, but it's not translating everything.
     
  3. Calamity_Jones

    Calamity_Jones

    Joined:
    Jul 31, 2019
    Posts:
    25
    I can confirm from further testing that any form of screen rotation is causing a crash. I made a build with auto rotate enabled, and the app was crashing. So this issue does not seem to have any relation to the level loading process, and seems to be entirely caused by rotation.... Can anybody help me?
     
  4. robertas-unity

    robertas-unity

    QA Minion Unity Technologies

    Joined:
    Mar 24, 2015
    Posts:
    28
    Hi! Thanks for reaching out.

    First of all, to be able to investigate and help, we'll need to get a bit more information about your setup:
    - which Unity version are you using?
    - what iOS versions are installed on your testing devices?

    It would be best if you could report a bug via the Unity editor and gather all the relevant info, as well as attach the repro project, there. You can post the bug ID here once you do that so that we could get to it quicker.
     
  5. Alexey

    Alexey

    Unity Technologies

    Joined:
    May 10, 2010
    Posts:
    1,602
    >>4 UnityFramework 0x0000000103b168f4 ApiGLES::Clear(unsigned int, ColorRGBAf const&, bool, float, int)
    please, please stop using opengles - apple have deprecated it long time ago (that kinda explains why you see it only with new devices). That sounds like some error in their gles implementation with metal. Nobody would fix it.
    "Just" update your app to use metal
    Sure, still, bugreport with repro project and information about unity version etc, just saying that it is time to move on
     
  6. JenaMarbotic

    JenaMarbotic

    Joined:
    Oct 22, 2021
    Posts:
    2
    Hi, sorry to open this post back but we have some of our users that run our app on IPad 4 and it doesn't support metal so we can't "just" upgrade to metal.
    I've made a bug report and discovered this post afterwards, any chance that there's going to be a fix anytime soon ?
    The bug report