Search Unity

  1. Improved Prefab workflow (includes Nested Prefabs!), 2D isometric Tilemap and more! Get the 2018.3 Beta now.
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. Let us know a bit about your interests, and if you'd like to become more directly involved. Take our survey!
    Dismiss Notice
  4. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice
  5. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice

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

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

  1. TheGoopyPixel

    TheGoopyPixel

    Joined:
    Apr 29, 2017
    Posts:
    181
    (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:
    1,720
    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.