Unity (in most cases because they're using an old version of Mono) has some quirks which cause otherwise "perfect" code to crash in certain circumstances:
- The Ahead-Of-Time (AOT) compilation may cause certain totally legitimate C# constructs like IEnumerable<T>.GetEnumerator to crash at runtime.
- On iOS, the default List<T>() constructor will set the internal array reference to a common static empty array, which is used until you add to the list. For some reason, performing .Add at the same time on multiple threads when each (distinct!) list is empty can crash even though the common static array is immutable. (Normally this is completely safe to do in C#.)
- We've seen interface properties become "corrupt" on Android. They will occasionally, for no apparent reason, start calling a different property's getter instead, returning garbage. Normally this is impossible, so I suspect there's a problem either in one of our native libraries corrupting memory, or in mono's ARM JIT compiler.
Normally you won't encounter these issues unless you're doing very specific things in your code, but they're something to take into account - you have to write code *slightly* differently from normal C# when using Unity.
There are some things that you can logically prove *cannot* crash by itself on .Net, but that same code can *totally* crash if you put it in a Unity project with a bunch of native plugins that play fast & loose with memory.
Edited by Nypyren, 12 May 2014 - 07:57 PM.