Can't compile using il2cpp in Unity

Issue #15 resolved
Former user created an issue

It seems the IL patching causes il2cpp to crash when compiling for Android in Unity with no additional information. Any ideas as to the problem?

Comments (11)

  1. Nicholas Woodfield repo owner

    I don't use Unity, we've had plenty of users of Unity use it...although I don't know if those projects are using il2cpp. The managed library has been updated to target .net standard 1.3 and uses a slightly different IL weaving strategy. If you're still monitoring this issue, you may want to give it a try.

    It could also be that il2cpp just isn't compatible with what we're doing.

  2. Nicholas Woodfield repo owner

    Fyi, I'm seeing an error with the latest build when using IL2CPP. One of the MemoryHelper::Read methods. Exception from IL2CPP is a not implemented exception, so it might very well be a bug on their end. It'll require deeper digging.

  3. Nicholas Woodfield repo owner

    I've submitted a bug report to Unity regarding this. I think I've narrowed it down to MemoryHelper methods that make use of the 'cpobj' IL instruction. The methods that would be affected are:

    • MemoryHelper::Read<T>(IntPtr, out T)
    • MemoryHelper::Write<T>(IntPtr, in T)

    'cpobj' is used in the singular copy operations where as 'cpblk' is used in the array operations. I see the same build problem if I reference the library SharpDX in my test unity project (many of my interop methods are based on theirs).

    The read method can be replaced by the non-out version, which uses 'ldobj' to do the copy (it probably will be inlined in released code anyways) - it only is used in one other place in the code. But the write method doesn't have a substitute and is used in a lot of places.

    The only viable way to fix this would be to make a change in my ILPatcher (which is a separate project), and use cpblk instead of cpobj. I am not sure of the performance implications, although ideally I'd rather see this fixed in Unity's IL2CPP backend.

  4. Denver Coulson

    Have you heard anything from your submitted bug report? We are likewise running into this trying to figure out whether we should try resolving ourselves.

  5. Nicholas Woodfield repo owner

    FYI,

    I'm kind of shocked it took this long, but today I got a response from their QA team acknowledging the issue and it's been sent for resolution to their development team.

  6. Drago Rosson

    Is there any update to this issue?

    @nickbenton Is there an issue in https://issuetracker.unity3d.com/ for this?

  7. Nicholas Woodfield repo owner

    They decided not to fix it in IL2CPP.

    I’ve updated my ILPatcher to not use the ‘cpobj’ instruction. I did some light testing with IL2CPP and it seems like it’s okay now. The 5.0.0-beta1 nuget package is out so you can give it a try.

  8. Hamid Younesy

    Hello@Nicholas Woodfield , Could you please elaborate more on your solution? How did you update ILPatcher not to use cpobj insturction?

    On OSX, I can build a standalone Unity app with 4.1.0, if I use Mono, but I get the following build error if I use IL2CPP :

    Il2cppBuildCache/macOS/x64/il2cppOutput/GenericMethods6.cpp:47380:8: error: no viable overloaded '='
    *L_0 = *L_2;
    ~~~~ ^ ~~~~
    

    Also, I tried the 5.0.0-beta1, and it doesn’t seem to work even with Mono or in Unity Editor. I get the following runtime exception (Editor, OSX):

    System.NullReferenceException: Object reference not set to an instance of an object
      at System.Buffer.memcpy4 (System.Byte* dest, System.Byte* src, System.Int32 size) [0x0000e] in <9577ac7a62ef43179789031239ba8798>:0 
      at System.Buffer.Memcpy (System.Byte* dest, System.Byte* src, System.Int32 size) [0x00073] in <9577ac7a62ef43179789031239ba8798>:0 
      at System.String.memcpy (System.Byte* dest, System.Byte* src, System.Int32 size) [0x00000] in <9577ac7a62ef43179789031239ba8798>:0 
      at Assimp.MemoryHelper.Read[T] (System.IntPtr pSrc, T[] data, System.Int32 startIndexInArray, System.Int32 count) [0x00008] in <d40f2b0ad6814d4c8094142d8473733f>:0 
      at Assimp.Unmanaged.AiString.GetString (Assimp.Unmanaged.AiString& aiStr) [0x0002d] in <d40f2b0ad6814d4c8094142d8473733f>:0 
      at Assimp.Mesh.Assimp.IMarshalable<Assimp.Mesh,Assimp.Unmanaged.AiMesh>.FromNative (Assimp.Unmanaged.AiMesh& nativeValue) [0x0000d] in <d40f2b0ad6814d4c8094142d8473733f>:0 
      at Assimp.MemoryHelper.FromNativeArray[Managed,Native] (System.IntPtr nativeArray, System.Int32 length, System.Boolean arrayOfPointers) [0x0006d] in <d40f2b0ad6814d4c8094142d8473733f>:0 
      at Assimp.Scene.Assimp.IMarshalable<Assimp.Scene,Assimp.Unmanaged.AiScene>.FromNative (Assimp.Unmanaged.AiScene& nativeValue) [0x00088] in <d40f2b0ad6814d4c8094142d8473733f>:0 
      at Assimp.MemoryHelper.FromNativePointer[Managed,Native] (System.IntPtr ptr) [0x0003b] in <d40f2b0ad6814d4c8094142d8473733f>:0 
      at Assimp.Scene.FromUnmanagedScene (System.IntPtr scenePtr) [0x0000f] in <d40f2b0ad6814d4c8094142d8473733f>:0 
      at Assimp.AssimpContext.ImportFile (System.String file, Assimp.PostProcessSteps postProcessFlags) [0x0009d] in <d40f2b0ad6814d4c8094142d8473733f>:0 
      at Assimp.AssimpContext.ImportFile (System.String file) [0x00000] in <d40f2b0ad6814d4c8094142d8473733f>:0 
    

  9. Log in to comment