Stack Overflow crashing... my computer?

Hi.
So i made a little mistake in which a “while” function within my code would never reach its ending condition.
So a stack overflow happened.
But Unity didn’t handle it at all? I had to reboot my PC 3 times to get the code working
Is this something normal?
Am i doing something wrong?
Any light on the subject would be nice.
Cheers!

A stack overflow should raise an exception and be handled by Unity. Or do you mean your while loop is an infinite loop? Because that would freeze Unity. Unfortunately Unity does nothing against that. But it should not crash other application. When that happens, terminating the Unity process is enough, no need to restart the computer.

The latter, my while loop was an infinite loop
It does Freezes Unity and then takes up so much memory on my PC that everything else stops working almost instantly
I’m keeping a Task Manager window open 24/7 to terminate Unity as fast as possible if this happens again.
This is just too bad, i use to work on Flash and this kind of errors would be handled with ease.
Oh well.
Thanks for answer anyways.

Unfortunately there is no way to break Unity out of an infinite loop without force quitting it.

1 Like

I’m afraid you’ve already figured out the best way to handle the situation. Just take more care of the stopping condition of your loops.

2 Likes

Whenever i make a new while loop, i always add a loop counter to terminate it at if it runs more than i anticipate, until i can be sure theres no way it’ll do this

2 Likes

Not a bad idea. NASA has the same requirement for space probes.

I personally save the project after every new while loop. And on a coroutine the first line I write inside a new while loop is always yield return null.

1 Like