Search Unity

Resolved IL2CPP AOT exceptions when loading SubScenes in a build

Discussion in 'Windows' started by brute-, Nov 15, 2021.

  1. brute-

    brute-

    Joined:
    Mar 2, 2013
    Posts:
    18
    I recently upgraded from 2020.3.8f1 to 2021.2.0f1. Trying to load SubScenes in a build now throws the following exceptions. The build is using IL2CPP and the WindowsBuildConfiguration build pipeline.

    Code (CSharp):
    1. ExecutionEngineException: Attempting to call method 'Unity.Entities.FastEquality+GetHashCodeImpl`1[[Unity.Entities.SceneSection, Unity.Entities, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null]]::GetHashCodeFunc' for which no ahead of time (AOT) code was generated.
    2. ExecutionEngineException: Attempting to call method 'Unity.Entities.FastEquality+CompareImpl`1[[Unity.Entities.SceneTag, Unity.Entities, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null]]::CompareFunc' for which no ahead of time (AOT) code was generated.
    This issue also reproduces in a blank HDRP project in 2021.2.2f1

    Anyone running into this problem?
    I've tried to add AOT stub code to pre-define Unity.Entities.SceneSection and SceneTag for the FastEquality generic methods, but nothing is working. Most of the class is private, so I cannot access GetHashCodeImpl or CompareImpl directly.
    I have also tried adding Unity.Entities namespace to link.xml. That didn't fix it. I don't think its a stripping issue anyways... rather IL2CPP has to explicitly define which types will be called by generic methods.

    Thanks
     
  2. Snuter

    Snuter

    Joined:
    Jul 13, 2019
    Posts:
    2
    Same issue here on Unity 2021.2.5f1... I got this error via logcat on android for my project:

    Error Unity ExecutionEngineException: Attempting to call method 'Unity.Entities.FastEquality+CompareImpl`1[[Unity.Rendering.FrozenRenderSceneTag, Unity.Rendering.Hybrid, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null]]::CompareFunc' for which no ahead of time (AOT) code was generated.

    I havn't found a solution yet.
     
    mikaelK and Nith666 like this.
  3. Nith666

    Nith666

    Joined:
    Aug 1, 2012
    Posts:
    56
    same error here. Upgraded to Unity 2021.2 from 2021.1 where everything worked fine
     
  4. Nith666

    Nith666

    Joined:
    Aug 1, 2012
    Posts:
    56
    For anyone who runs into this error: I was able to get rid of this error by changing the IL2CPP Code Generation (Build Settings window) to "Faster (smaller) builds". I also changed code stripping level to minimal, but I'm not sure if that had an effect
     
    lclemens, deus0, grofie and 1 other person like this.
  5. Snuter

    Snuter

    Joined:
    Jul 13, 2019
    Posts:
    2
    very nice... this also solved the issue on my side.

    Big thanks
     
    grofie and mikaelK like this.
  6. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,930
    Also note that with Unity 2022.1 and later, this error will not happen with with any IL2CPP Code Generation option. We have a blog post coming out this week with more details about this feature.
     
    lclemens and deus0 like this.
  7. brute-

    brute-

    Joined:
    Mar 2, 2013
    Posts:
    18
    This fixed my issue! Thanks everyone for the help ;)
     
  8. jackcheng

    jackcheng

    Joined:
    May 17, 2013
    Posts:
    12
    hi , where is that blog ? and how can 2021.3.x work around this issue without change IL2CPP Code Generation option
     
  9. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,930
    This is the blog post: https://blog.unity.com/technology/feature-preview-il2cpp-full-generic-sharing-in-unity-20221-beta

    You can work around the error by ensuring that the generic types with the generic type arguments mentioned in the error message are present at compile time. So you will need to write some code that is not used at run time, but is also preserved from managed code stripping which uses those types. Then IL2CPP will be able to generate that code, and avoid this error.
     
  10. jackcheng

    jackcheng

    Joined:
    May 17, 2013
    Posts:
    12
    try write some code in monobehavior but still got same error, and error only exist in android build , not in ios build.
    ........
    var sections = new List<SceneSection>();
    EntityManager.GetAllUniqueSharedComponentData(sections);
    for(int i = 0; i < sections.Count;i++)
    {
    var section = sections;
    var index = TypeManager.GetTypeIndex<SceneSection>();
    Debug.LogError($"SceneSection GetTypeIndex {index}");
    var type_info_m = TypeManager.GetTypeInfo(index);
    Debug.LogError($"SceneSection TypeManager type_info {type_info_m}");
    var type_info_f = TypeManager.GetFastEqualityTypeInfo(type_info_m);
    Debug.LogError($"SceneSection FastEquality type_info GetHashFn {type_info_f.GetHashFn}");
    var point = UnsafeUtility.AddressOf(ref section);
    HashSet<string> res = new HashSet<string>();
    FastEquality.AddExtraAOTTypes(typeof(SceneSection), res);
    Debug.LogError($"SceneSection AddExtraAOTTypes {res}");
    //GetHashCodeDelegate fn = (GetHashCodeDelegate)type_info_f.GetHashFn;
    //Debug.LogError($"SceneSection FastEquality GetHashFn {fn.Method.Name}");
    //var result = fn(ref section);
    //Debug.LogError($"SceneSection GetHashFn {result}");
    //CompareEqualDelegate efn = (CompareEqualDelegate)type_info_f.EqualFn;
    //Debug.LogError($"SceneSection FastEquality EqualFn {efn.Method.Name}");
    //var result_e = efn(ref section,ref section);
    //Debug.LogError($"SceneSection EqualFn {result_e}");
    var hascode = Unity.Entities.TypeManager.GetHashCode(section, index);
    Debug.LogError($"SceneSection {section.SceneGUID} hascode {hascode}");
    var hascode_fast = Unity.Entities.FastEquality.GetHashCode(section, type_info_f);
    Debug.LogError($"SceneSection FastEquality GetHashCode {hascode_fast}");
    }
    ......

    and error happen on this line
    Unity.Entities.TypeManager.GetHashCode(section, index);
     
  11. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,930
    I'm unsure what the problem is here. Do you see an error message?