Random hard crash on start, both in Editor and in Windows standalone build.

I’ve got a tricky problem. Lately when we start our application, it randomly crashes after one or two seconds. It’s a hard crash, a ‘Unity Editor has stopped working’ crash. When we make our Windows standalone build, it shows the same behaviour. I’d say it crashes roughly 1 out of every 4 times, but it’s very unpredictable.

98077-crashmsg.png

Windows offers to debug it, and although we don’t have the Unity or Mono source code we do get a more specific error message:
“Unhandled exception at 0x00007ff82f5d2cfd (mono.dll) in Unity.exe: 0xC0000005: Access violation reading location 0x000000000000000000.”. See image for callstack.

We recently added a large new UI and also made a number of changes to our C# code. Hard to pin down which change caused it because the crashes are so random you don’t know if a fix worked or not.

Any tips on how to debug this?

We’re using Unity 5.6.1f1 64bit on Windows. We have about 10 asset store plugins like Mega-Fiers and Unity-UI-Extensions.

I ended up writing a powershell script to continually start it and kill it after 10 seconds. If it was not responding or not alive after 10 seconds, I would mark it as failed. Using this script I started testing different commits and finally found the offending one.

Turns out I was calling stuff from System.Drawing.Image in multiple threads, like Image.FromFile and Image.Save. From what I (now) understand System.Drawing.Image doesn’t like multithreading. This was causing the hard crashes.

Unfortunately I don’t see any alternative Image processing libraries that are compatible with Unity’s current version of mono… so I’m going to try going single threaded when loading those images and see if that works.