- Home /
Templates/Generic - AOT problems
Hi,
I ran into some problem using generics/templates in Unity while deploying my code to iPad.
Here is some simple code :
using UnityEngine;"
using System.Collections;
using System.Collections.Generic;
class TestValue<T>
{
public T _value;
public TestValue(T _p)
{
_value = _p;
}
}
class TestDictonary<T>
{
public Dictionary< TestValue<T>, int> _dic;
public TestDictonary(T _p)
{
_dic = new Dictionary<TestValue<T>, int>();
_dic.Add(new TestValue<T>(_p), 2);
}
public void PrintAll()
{
Debug.Log( _dic.Values.Count );
}
}
public class TestLogging : MonoBehaviour
{
void Awake()
{
TestDictonary<string> myDictionary = new TestDictonary<string>("Yep");
myDictionary.PrintAll();
}
}
While running this on my iPad i got:
ExecutionEngineException: Attempting to JIT compile method 'System.Collections.Generic.Dictionary`2 int>:.ctor ()' while running with > --aot-only.
I have done some research and it seems a common problem ( http://ios.xamarin.com/Documentation/Limitations )
What I dont get is how could I discover that before (ie not at runtime) ? Why is there no errors reported during compilation ?
The compilation under unity is done with the flag --aot=full ... so why such cases aren't be discovered there ?
Here is the Unity command line i had discovered in the logs - note how AOT is set to full.
AOT cross compiler: /Applications/Unity.app/Contents/BuildTargetTools/iPhonePlayer/mono-xcompiler --debug --aot=full,asmonly,write-symbols,soft-debug,static,outfile="Assembly-CSharp.dll.s" "Assembly-CSharp.dll" current dir : /Users/XXXX/Dev/Unity/TestLogging/Temp/StagingArea/Data/Managed
Answer by KvanteTore · Oct 06, 2011 at 10:21 AM
Actually, according to the limitations document you referenced it looks like it should work, as your TestValue is a reference type and not a value type.
However, you could try providing your own IEqualityComparer to the dictionary constructor and see if that helps.
Unfortunately, I have not been able to find a reliable way of determining if a piece of code code will run on iOS without actually uploading the app and running it.
Your answer
Follow this Question
Related Questions
Unity compilation process - JIT and AOT? 1 Answer
iOS JIT compile error on Generic method called with basic types (int, bool, float) 1 Answer
How does Unity compilation work? 1 Answer
generic / templatized components / monobehaviors ? 0 Answers
ExecutionEngineException : JIT/AOT error when adding to delegate 1 Answer