Search Unity

Unity 5.2 crash when Application.LoadLevel is called at Start (with UI in the first scene)

Discussion in 'Editor & General Support' started by BenouKat, Sep 9, 2015.

  1. BenouKat

    BenouKat

    Joined:
    Feb 29, 2012
    Posts:
    222
    Hi,

    My project is instantly crash when I launch it. My object aren't sorted by Alphabetical order (so it's not the DontDestroyOnLoad issue).

    Here is my crash log. Anyone experienced crash issue ? Two project of our team can't run Unity 5.2 without a crash in a minute in the editor, or instant crash by pressing play.

    We are pretty disappointed here as all unity upgrades since 5.0 never doing bad stuff like this in the past.

    EDIT 1 : More information, we figure out that we crash when we are changing scene. I'm still investigate.
    EDIT 2 : We found the issue : if Application.LoadLevel is called in Start(), the editor crash. I'm looking for a test project for issue tracker

    EDIT 3 : We reproduce it :
    1) Make two scenes
    2) Import some images, set in Sprite mode
    3) Right click on scene -> UI -> Image, it wille create a simple canvas with an image inside
    4) Put one of the image imported on the Image component
    5) Make a script that do Application.LoadLevel("Scene2") on Start
    6) Run -> profit the crash.
     

    Attached Files:

    Last edited: Sep 9, 2015
  2. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,291
    Thanks. We have been able to recreate it and are now investigating.
     
  3. BenouKat

    BenouKat

    Joined:
    Feb 29, 2012
    Posts:
    222
    Thanks, I posted an issue into the issue tracker just after I edit my post here with my example project.
     
  4. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,291
    Yes I found it, thanks that's always the best thing to do so we can keep track :)
     
  5. Gardosen

    Gardosen

    Joined:
    Oct 25, 2014
    Posts:
    39
    thank you for showing this up, I have exactly the same problem and I was scared that it is related with my Smartfox implementation :O

    I will go for a workarround with calling the ApplicationLoad over a different method after switching a flag in the start method.
     
    karl_jones likes this.
  6. BenouKat

    BenouKat

    Joined:
    Feb 29, 2012
    Posts:
    222
    You can just call a coroutine and call your level after a "yield return 0", it will skip the first frame and do the trick ! :)
     
    karl_jones likes this.
  7. Gardosen

    Gardosen

    Joined:
    Oct 25, 2014
    Posts:
    39
    hmm :(

    i am not that familar with Coroutines. i tryed this, but my Unity still Crashs :/

    i wrote this and i am calling it on Start() with StartWorkaround();

    Code (CSharp):
    1.     IEnumerator Workaround() {
    2.         yield return 0;
    3.     }
    4.  
    5.     IEnumerator StartWorkaround() {
    6.         yield return StartCoroutine("Workaround");
    7.     }
    what exactly is wrong here?

    PS.: For now i was able to solve my problem by changing the method from Start to Awake, not a nice workaround but it works.

    Kind regards
    Tepoo
     
    Last edited: Sep 9, 2015
  8. TimGS

    TimGS

    Joined:
    Apr 24, 2014
    Posts:
    70
    Well... Almost everything. =)

    You should do something like this:
    Code (csharp):
    1. void Start()
    2. {
    3.     StartCoroutine("LoadMyLevel");
    4. }
    5.  
    6. IEnumerator LoadMyLevel()
    7. {
    8.     yeild return null;
    9.     Application.LoadLevel("MyLevel");
    10. }
     
    karl_jones likes this.
  9. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,291
    The start function can be a coroutine so you could do:

    Code (csharp):
    1. IEnumerator Start()
    2. {
    3.     yeild return null;
    4.     Application.LoadLevel("MyLevel");
    5. }
     
  10. TimGS

    TimGS

    Joined:
    Apr 24, 2014
    Posts:
    70
    Oh, thank you. Documentation seems to be missing this info, never read that.
     
  11. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,291
    Yes it does not seem to be mentioned in the docs, we will fix that :D
     
  12. BenouKat

    BenouKat

    Joined:
    Feb 29, 2012
    Posts:
    222
    Wow, im learning new things day after day even after 3 years of Unity dev :D
     
    karl_jones likes this.
  13. Gardosen

    Gardosen

    Joined:
    Oct 25, 2014
    Posts:
    39
    thanks for this information :)

    currently i am lucky that i don't need coroutines yet, but if the day comes, i know something more then yesterday :D

    you guys are doing a good job :)
    Keep up the great work.
     
  14. actraiser3

    actraiser3

    Joined:
    Sep 11, 2014
    Posts:
    28
    I noticed that you can also simply replace Application.LoadLevel ("yourscene") in Start() with Application.LoadLevelAsync ("yourscene"). That stopped the crashes for me.

    -act
     
    karl_jones likes this.
  15. TechiTech

    TechiTech

    Joined:
    Dec 13, 2014
    Posts:
    212
    Just tried that but unity just freezes instead of crashing to desktop :/
     
  16. phil-Unity

    phil-Unity

    Unity UI Lead Developer

    Joined:
    Nov 23, 2012
    Posts:
    1,226
    Taking a look, we seem to have a fix somewhere but it's not clear what change to fix it.
     
    karl_jones likes this.
  17. TechiTech

    TechiTech

    Joined:
    Dec 13, 2014
    Posts:
    212
    oh i see... you guys will figure it out I'm sure.
     
  18. BestCommie

    BestCommie

    Joined:
    Sep 28, 2015
    Posts:
    8
    Same with crash here after upgrading to 5.2.1f1 from 5.1.something, i enabled a game object that was responsible for changing scenes and editor crashes.
    Compiled version does not crash but compiling doesn't help testing.
    Whatever you changed in the last update most probably broke it.
    Application.LoadLevel crashes if it's called at Start or Update BUT it WORKS if it's called on Awake.
    LoadLevelAsync works EVERYWHERE. This is not a solution however :(
     
    Last edited: Oct 7, 2015
    actraiser3 likes this.
  19. actraiser3

    actraiser3

    Joined:
    Sep 11, 2014
    Posts:
    28
    This problem also persists with the latest patch release 5.2.1p2 . I also still have to use async load at the moment to not crash the editor. @phil-Unity, could you kindly recheck on your statement that there is a fix somewhere and the state of its integration in a future release? Thanks!

    -act
     
  20. FuzzyQuills

    FuzzyQuills

    Joined:
    Jun 8, 2013
    Posts:
    2,871
    Well, lucky for me that I use async for an animated loading screen then. ;) I also still have 5.2.0f3
     
  21. any_user

    any_user

    Joined:
    Oct 19, 2008
    Posts:
    374
  22. ArBuZ

    ArBuZ

    Joined:
    Dec 27, 2012
    Posts:
    9
    The problem still exists. I have this problem if there is Canvas in the scene. If I remove or disable the canvas, everything works fine
     
  23. Shushustorm

    Shushustorm

    Joined:
    Jan 6, 2014
    Posts:
    1,084
    Have you tried using the current version (5.2.2) of Unity?
     
  24. FuzzyQuills

    FuzzyQuills

    Joined:
    Jun 8, 2013
    Posts:
    2,871
    Actually, one thing I forgot to mention a while ago; I did find that if I had more than one UI canvas in a scene, the scene would freeze up after a random amount of seconds, forcing me to close it. Could be related? (I haven't tried again yet either...)
     
  25. ArBuZ

    ArBuZ

    Joined:
    Dec 27, 2012
    Posts:
    9
    Yes. The issue presents in the last version
     
    Shushustorm likes this.
  26. FuzzyQuills

    FuzzyQuills

    Joined:
    Jun 8, 2013
    Posts:
    2,871
    Being that I use LoadLevelAsync, I am going to have to see if I'm affected by this bug... :D
     
  27. actraiser3

    actraiser3

    Joined:
    Sep 11, 2014
    Posts:
    28
    Fyi, todays release of Unity 5.2.3 seems to have fixed the problem for me.

    -act
     
    FuzzyQuills and karl_jones like this.
  28. FuzzyQuills

    FuzzyQuills

    Joined:
    Jun 8, 2013
    Posts:
    2,871
    Which platforms? Also, good to hear that problem seems to be fixed. :)
     
  29. actraiser3

    actraiser3

    Joined:
    Sep 11, 2014
    Posts:
    28
    This was a problem with the Editor only (OSX in my case). It's not related to running code on build targets.

    -act
     
  30. FuzzyQuills

    FuzzyQuills

    Joined:
    Jun 8, 2013
    Posts:
    2,871
    Ok then. :)
     
  31. superdiederik

    superdiederik

    Joined:
    Apr 25, 2012
    Posts:
    32
    Hi all!

    Ran into a similar (or the same) issue over here using the 5.3.1 editor and calling Appliation.LoadLevel...
    Not sure if it's UI (I use NGUI) related or not.
    But I used LoadLevel in Awake and the Editor crashed.
    Now I changed this...
    using UnityEngine.SceneManagement;
    and then
    SceneManager.LoadScene("MyScene")
    This fixed the issue (since Application.LoadLevel is becoming obsolete).
    Hope this information helps someone... :)

    Diederik / Xform

    EDIT: The problem came back strangely enough, so I'm guessing it's the issue that you cannot call this in Awake anymore. So I guess this issue is not fixed yet.
     
    Last edited: Dec 22, 2015
  32. ekt

    ekt

    Joined:
    Jul 9, 2012
    Posts:
    28