#Coroutines, while (true), infinite loops, and the Unity Editor

1 messages · Page 1 of 1 (latest)

high abyss
#

I figured out that a coroutine I have (which was previously working fine) is now causing my Unity Editor to hang up when I press play. Here is the coroutine:

IEnumerator Controller()
    {
        // wait for pheromones to be assigned, access the first pheromone
        int currentPheromoneIndex = 0;
        while (pheromoneSequence.Length == 0)
        {
            yield return null;
        }
        currentPheromone = pheromoneSequence[currentPheromoneIndex];

        // begin obeying pheromones
        while (true);
        {
           // ... controller logic goes here ...
           yield return null;
        }
    }
#

But I do have other while(trues elsewhere in my code that aren't causing an issue? What's the deal?

quiet flame
#

Are you accidentally calling this function directly? Controller() instead of StartCoroutine(Controller())?

high abyss
#
void Start()
    {
        transform.position = colony.transform.position + new Vector3(0, 10, 0);
        antState = AntState.Idle;
        pheromoneState = PheromoneState.InProgress;

        StartCoroutine(Controller());
    }
#

No

quiet flame
#

It might be being called somewhere else too

high abyss
#

Oh, well, I said I was calling other coroutines with infinite loops without a problem, but that's actually not true anymore. The Controller is meant to call Continue, another infinite-loop coroutine that gets stopped also by the Controller

high abyss
quiet flame
high abyss
#

Which I'm all but certain I'm not :/

#

Weird, bc yesterday it was working until I started messing around with enums.

#

Well also I added something else, too

quiet flame
high abyss
#

For sure

#

Works fine when the Controller isn't called. No surprise.

#

Works fine when the second loop of the Controller is commented out.

primal hornet
high abyss
#

oh, it's currently commented

primal hornet
#

very easy for "... controller logic" to contain the problem

high abyss
#

and even so it hangs up

#

no, that is currently commented out

primal hornet
#

youi have a semicolon there

#

delete it

high abyss
#

LOL OMG

primal hornet
#

that's your problem

high abyss
#

SORRY Y'ALL

primal hornet
#

your IDE should be giving you a squiggle too 😉

quiet flame
#

Dang, I shoulda noticed that

high abyss
#

using free VSCode, not getting squiggles >.>

#

lol thanks champs

primal hornet
glass nymphBOT
#
💡 IDE Configuration

If your IDE is not autocompleting code
or underlining errors, please configure it:

Visual Studio (Installed via Unity Hub)
Visual Studio (Installed manually)

VS Code*
JetBrains Rider
Other/None

*VS Code's debugger plugin is unsupported.
We recommend using VS or Rider instead.

primal hornet
#

You can get squiggles with vscode, and should configure it

high abyss
#

nice thanks!!