Search Unity

Putting 'StartCoroutine(xxx());' inside of the same coroutine causes Unity2018.1.0f2 to go crazy

Discussion in 'Scripting' started by VileGoo, Aug 12, 2018.

  1. VileGoo

    VileGoo

    Joined:
    Apr 29, 2017
    Posts:
    220
    (the xxx is just an example name and not the actual coroutine name, fyi)

    I was making a simple coroutine that just counts down a variable over time and then ends the coroutine after the variable is 0 by running 'StopCoroutine(xxx());'

    But it wasn't like this at first, It auto-completed to StartCoroutine and I didn't notice until I tested my game. Basically when the line was ran in the coroutine the game froze for a few seconds and then started getting mass spammed by "Assertion failed: TLS Allocator ALLOC_TEMP_THREAD, underlying allocator ALLOC_TEMP_THREAD has unfreed allocations, size 390" Fixing the line or even totally deleting the coroutine didn't fix it, it would just keep spamming the console with that error. Closing and restarting Unity seems to have fixed it, although I'm a bit worried I might've broken my project, there isn't as issues popping up at the moment, however.

    Has this bug been fixed in new versions of Unity? If not then perhaps you could add an error in the console saying "you can't start the same coroutine inside of the coroutine" or something.
     
  2. GroZZleR

    GroZZleR

    Joined:
    Feb 1, 2015
    Posts:
    3,201
    Your project is fine. You just created infinite recursion which blew up the stack, and I guess corrupted something internally in Unity, so restarting is fine.

    There's nothing wrong with calling a coroutine from within itself, you just can't do it infinitely as you had.
     
    Kiwasi likes this.
  3. mouhamedniagal

    mouhamedniagal

    Joined:
    Jul 20, 2020
    Posts:
    1