Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

[Error] ToDeferredJobArray not working with IL2CPP standalone

Discussion in 'Entity Component System' started by slim_trunks, Oct 8, 2018.

  1. slim_trunks

    slim_trunks

    Joined:
    Dec 31, 2017
    Posts:
    41
    I'm encountering this error message in game at start up time when building with IL2CPP for Windows standalone:

    Code (CSharp):
    1.  
    2. ExecutionEngineException: Attempting to call method 'Unity.Jobs.IJobParallelForExtensions+ParallelForJobStruct`1[[MeshGeneratorEx+MeshGenerationJob, Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null]]::Initialize' for which no ahead of time (AOT) code was generated.
    3. at System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture)        [0x00000] in <00000000000000000000000000000000>:0
    4. at System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) [0x00000] in        <00000000000000000000000000000000>:0
    5. at Unity.Jobs.IJobParallelForDeferExtensions+ParallelForJobStruct`1[T].Initialize () [0x00000] in                      <00000000000000000000000000000000>:0
    6. at MeshGeneratorEx.Start () [0x00000] in <00000000000000000000000000000000>:0
    7.  
    where MeshGenerationJob gets passed a NativeArray via the NativeList.ToDeferredJobArray method.
    This error message seems very similar to this one::https://forum.unity.com/threads/win...ossible-to-show-the-type-in-the-error.526455/

    Looking at the source code for
    IJobParallelForDeferredExtensions.ParallelForJobStruct<T>.Initialize()
    I found that it is using the
    MakeGenericType 
    method which seems to be related to this issue.(see https://forum.unity.com/threads/il2cpp-type-makegenerictype-work-around.311926/)

    Before finding out about all this I tried to keep il2cpp from stripping the Unity.Jobs assembly with the approach described here: https://docs.unity3d.com/Manual/IL2CPP-BytecodeStripping.html
    Didn't work, error message keeps appearing.

    I <redacted> IJobParallelForDeferredExtensions so I could instantiate a generic instance of the
    ParallelForJobStruct
    as was described in the first link as a workaround.
    Didn't work, error message keeps appearing.

    As I'm writing this I'm looking at the error message again and seeing that it is referring specifically to IJobParallelForExtensions so maybe I need to instantiate a ParallelForJobStruct of that type as well.
    Didn't try this yet.

    Is this a known issue, is it related to what I found out about il2cpp and MakeGenericType and if so is there any fix for this?
     
    Last edited: Oct 8, 2018
  2. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
    Where did you find IJobParallelForDeferredExtensions? I am not aware of such a thing.
     
  3. slim_trunks

    slim_trunks

    Joined:
    Dec 31, 2017
    Posts:
    41
    I went into the Local/Unity folder where the cached packages are located. It was inside the Unity.Jobs package folder.
    I'm using the staging packages server but the cs file is found in both the staging and non-staging cache folder.

    Edit: the Schedule extension method for deferred job arrays is also located in this file.
     
  4. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
    Can you upgrade to a newer version, this code no longer exists.
     
  5. slim_trunks

    slim_trunks

    Joined:
    Dec 31, 2017
    Posts:
    41
    Okay, I'm on 2018.3.0b4 now. Was on the current build of 2018.2. I removed the staging-packages server from my manifest.json and reinstalled all the packages.
    The error is still there when building with il2cpp.
    I'm on Jobs 0.0.7-preview.4 and the
    IJobParallelForDeferredExtensions
    keeps getting downloaded.
     
  6. slim_trunks

    slim_trunks

    Joined:
    Dec 31, 2017
    Posts:
    41
    It seems that I made a spelling mistake. The file is actually called IJobParallelForDeferExtensions.cs.
    I tried reinstalling the Jobs package after having deleted every cached version in the Local/Unity/cache directory. Both in npm and packages but I still get the same file in 0.0.7-preview.4.

    Also tried reaching into IJobParallelForExtensions to instantiate the ParallelForJobStruct and used the il2cpp_extra_types.txt method. Both showed no improvement.

    I'm now hoping that this fixes itself when a new Jobs version is rolled out.
     
  7. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
    Ok I see. Implementation is not correct. We'll see what we can do.
     
  8. slim_trunks

    slim_trunks

    Joined:
    Dec 31, 2017
    Posts:
    41
    That's good to hear. Thank you for looking into this. I'm looking forward to any news.
     
  9. LennartJohansen

    LennartJohansen

    Joined:
    Dec 1, 2014
    Posts:
    2,394
    Do you know if this is fixed? I am getting a similar error.

    Lennart