A few people have reported random freezes in my game, running the Windows build, and I’ve also had it happen once myself.
The Issue
You’re playing the game, not doing anything in particular, then suddenly it freezes, the audio starts looping the same ~1-second buffered section over and over, and you have to force quit the frozen game.
It’s super rare - I’ve only had it happen once and I’ve never had anyone who reported it ever get it again - and nothing appears in the output_log.txt. I could hook of a dev build, but I’d probably never get the crash to happen, and even if I did I suspect it’d leave no information on what happened.
Specs
The machine I had it happen on once was a 2012 Macbook Pro running Windows 7. The game is built in the latest Unity 4.6. Memory use is fine, and the game runs perfectly the other 99% of the time.
Questions
Has anyone else had random freeze crashes like this? I can only find results about editor crashes or crashes that happen immediately on play. This crash seems to happen any time.
Is there any way to get more information on what happens when a program freezes and just has to be force quit like this? Like, does Windows dump some info somewhere? The’re no crash dialog since it’s a freeze rather than a straight crash.
I have no idea how to track this one down barring just upgrading to Unity 5 and hoping it’s fixed. I’ve got 30,000+ lines of code and a crash that seems like it’s probably something deeper in the Unity engine anyway and is near-unreproducible.
Sometimes those infinite loops can sneak up where you don’t expect them.
I had an RTS where bases were randomly generated, and the game would keep relocating random positions until all the bases were far enough apart. That didn’t cause problems for a long time, until one day our game just froze up, not responding until we forced it quit. It turns out, if the first few random placements were juuuuust right, it would become impossible to fit the rest of the bases in the given area, and our game would endlessly try to no avail.
Try putting some checks in some loops that you think might be the culprit. You can throw some debug logs that will let you know from the message what loop it’s in so you can check for those logs next time you crash.
Infinite loop is definitely possible, although if it was totally frozen due to an infinite loop, I’m not sure I’d still get the looping ~1s of buffered audio playing like this does. Maybe I should test that.
Unity may do audio differently, but when I made an audio system outside unity, I had to update my audio system each frame and send in deltaTime. Not doing so would give strange and unpredictable results.
Unity normally updates their internal systems in the background, but if you take over the main thread with an infinite loop, the only thing unity can do by itself is something that it has already started on a different thread, and Unity doesn’t use much of multithreading.