Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice

2017.1.0b7: (Case 915463) Coroutine stuck after yield return null

Discussion in '2017.1 Beta' started by Peter77, May 28, 2017.

  1. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    6,620
    Doing a "yield return null" inside a while-loop of a coroutine never returns. It enters the first while-loop iteration, but then never continues after the yield.The problem exists in the editor and player.

    Please consider the following coroutine code (copied from Loading.cs):
    Code (CSharp):
    1. Debug.Log("#1");
    2.  
    3. // Fade out
    4. Time.timeScale = 0;
    5. while (transition.alpha < 1)
    6. {
    7.     transition.alpha += Time.unscaledDeltaTime * invDuration;
    8.     AudioListener.volume = Mathf.Clamp01(1 - transition.alpha);
    9.  
    10.     Debug.LogFormat("#1: while ({0} < 1)", transition.alpha);
    11.     yield return null;
    12. }
    13. AudioListener.volume = 0;
    14.  
    15. Debug.Log("#2");

    Running this code in Unity 5.5.2p4 outputs the following text to the Console window:
    Code (CSharp):
    1. #1
    2. #1: while (0.01929984 < 1)
    3. #1: while (0.3549189 < 1)
    4. ...
    5. #1: while (1 < 1)
    6. #2

    Running the same code in Unity 2017.1.0b7 outputsthe following text to the Console window:
    Code (CSharp):
    1. #1
    2. #1: while (0.01791501 < 1)
    The 2nd while-loop iteration never gets executed.


    Reproduce 2017.1.0b7
    • Open user project in 2017.1.0b7
    • Open Scenes/Booting/Booting.unity
    • Press PLAY
    Notice the game displays a black screen and outputs the following text to the Console window:
    #1
    #1: while (0.01791501 < 1)


    Reproduce 5.5.2p4
    • Open user project in 5.5.2p4
    • Open Scenes/Booting/Booting.unity
    • Press PLAY
    Notice the game displays an animated loading screen. I've attached the 5.5.2p4 project (unity_5_5_2p4_project.zip) to the bug-report as well, in case you can't open the submitted 2017 project in 5.5 to verify.


    Expected
    The coroutine should continue to run the while-loop after the first yield.
     
  2. HarryCodder

    HarryCodder

    Joined:
    Feb 20, 2015
    Posts:
    84
    Hi,

    I was wondering if anyone else has seen weird behaviors with coroutines in Unity 2017, did you have any answer from Unity about your case ?

    I can't find any reproduction scenario but sometimes coroutines just stop for no reason.
    It seems to affect the Test Runner too, freezing Unity completely when it happens.
    It's not just when yielding null, I saw it when yielding until end of frame too.

    Restarting Unity when this happens usually fixes the problem until it happens again.
     
  3. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    6,620
    I do, here is what they wrote me:
     
    rorylane likes this.