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

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.

2287109–153689–Crash.txt (92.5 KB)

Thanks. We have been able to recreate it and are now investigating.

Thanks, I posted an issue into the issue tracker just after I edit my post here with my example project.

Yes I found it, thanks that’s always the best thing to do so we can keep track :slight_smile:

thank you for showing this up, I have exactly the same problem and I was scared that it is related with my Smartfox implementation :open_mouth:

I will go for a workarround with calling the ApplicationLoad over a different method after switching a flag in the start method.

1 Like

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 ! :slight_smile:

1 Like

hmm :frowning:

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

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

    IEnumerator Workaround() {
        yield return 0;
    }

    IEnumerator StartWorkaround() {
        yield return StartCoroutine("Workaround");
    }

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

Well… Almost everything. =)

You should do something like this:

void Start()
{
    StartCoroutine("LoadMyLevel");
}

IEnumerator LoadMyLevel()
{
    yeild return null;
    Application.LoadLevel("MyLevel");
}
1 Like

The start function can be a coroutine so you could do:

IEnumerator Start()
{
    yeild return null;
    Application.LoadLevel("MyLevel");
}

Oh, thank you. Documentation seems to be missing this info, never read that.

Yes it does not seem to be mentioned in the docs, we will fix that :smile:

Wow, im learning new things day after day even after 3 years of Unity dev :smile:

1 Like

thanks for this information :slight_smile:

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

you guys are doing a good job :slight_smile:
Keep up the great work.

I noticed that you can also simply replace Application.LoadLevel (“yourscene”) in Start() with Application.LoadLevelAsync (“yourscene”). That stopped the crashes for me.

-act

1 Like

Just tried that but unity just freezes instead of crashing to desktop :confused:

Taking a look, we seem to have a fix somewhere but it’s not clear what change to fix it.

1 Like

oh i see… you guys will figure it out I’m sure.

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 :frowning:

1 Like

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

Well, lucky for me that I use async for an animated loading screen then. :wink: I also still have 5.2.0f3