Unity (randomly) freezing on play

Hey everyone. I have an annoying bug I can’t figure out. Unity freezes when I hit the play button (it doesn’t ever turn blue). The only thing I’ve seen on the forums is talk about infinite loops. I’m quite sure my loops aren’t infinite, but they aren’t deterministic either… let me explain:

Basically I’m randomly generating and placing a galaxy (starsystems-stars-planets-asteroids) inside a confined map. If a starsystem is within a certain range of another, then the placement will loop until it randomly finds a good spot. I don’t think this is the issue as I have a breaker inside that breaks upon too many iterations.

So that is guess #1

Guess # 2 is that the objects being placed have colliders (as triggers) and that unity can’t handle placing colliders when they are placed on top of each other.

If I place 10 starsystems (roughly 6 planets each). It crashed 30% of the time. If it goes up to 20, it’s like 100% crashes.

no errors, no debug statements. Also all the random generation is happening inside awake or start statements.

any thoughts?

I was able to solve this issue. I was using Random.Range(int, int) which makes the max int exclusive (Didn’t know that). For example I was placing 10 objects into 9 slots and the while loop would freeze on the last one searching for an open slot.

But even with that issue, I don’t understand why Unity didn’t die elegantly? I had break loops that would break after 100 tries. Yet I never got the flag…

Is this a Unity bug? If you break an iterator on awake/start shouldn’t Unity realize this and stop on start instead of just freezing/black screen.