Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Bug Debugging Unity hangs

Discussion in 'Editor & General Support' started by ivoras, Nov 30, 2021.

  1. ivoras

    ivoras

    Joined:
    May 21, 2020
    Posts:
    66
    I have a strange situation here where Unity usually hangs every *second* time I start the player from the editor. So, the first time I click Play, it starts normally, the second time I click it, it hangs after a couple of seconds.

    This is a pretty heavy-duty project, with a lot of network communication, asset bundle loading, complex game objects are spawning regularly, so it could be anything.

    I've tried attaching the VS debugger to Unity, but when the hang happens, I never see my code in stack traces, so I presume it always hangs in Unity-specific code, not in C# scripts.

    The editor log doesn't help.

    This is Unity 2021.1.25f1 (and I can't upgrade due do other Unity bugs, described at https://forum.unity.com/threads/importing-project-hangs-on-2021-2-4f1.1205206/)

    Has anyone tried to debug Unity itself and see where it hangs?
     
  2. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,646
    Can you show the stack traces view in VS? Generally, hanging while entering playmode means that Unity is waiting for spawned threads from previous playmode to exit.
     
  3. ivoras

    ivoras

    Joined:
    May 21, 2020
    Posts:
    66
    Well, thank you for pointing me in the right direction. While capturing the stack traces, I've noticed something which led me to actually solve the issue - it was my own fault after all, and one of the threads actually had C# code.

    There was a co-routine waiting for a flag set by another co-routine, and it didn't have a "yield return null" so that made it a potential infinite loop and the source of the hang, depending on which co-routine got scheduled to run first. Apparently it was an accident that in the second run the checking co-routine usually got scheduled before the setting one.

    We haven't noticed it before during development because previously that flag was always set.

    So, thanks :)