iOS runtime crash in Unity.Entities.Conversion.MultiList of ConvertGameObjectToEntitySystem

Hello everyone & Happy Holidays (aka time to work on our games… :smile: ),

I have a small IConvertGameObjectToEntity class doing the following:

    public class PrefabRegistryEntryAuthoring : MonoBehaviour, IConvertGameObjectToEntity {
        public PrefabRegistryIdentifier PrefabRegistryIdentifier;

        public void Convert(Entity entity, EntityManager entityManager, GameObjectConversionSystem gameObjectConversionSystem) {
            if (TryGetComponent<TrailRenderer>(out var trailRenderer)) {
                gameObjectConversionSystem.AddHybridComponent(trailRenderer);
            }
            if (TryGetComponent<ParticleSystem>(out var particleSystem)) {
                gameObjectConversionSystem.AddHybridComponent(particleSystem);
                if (TryGetComponent<ParticleSystemRenderer>(out var particleSystemRenderer)) {
                    gameObjectConversionSystem.AddHybridComponent(particleSystemRenderer);
                }
            }
        }
    }

While Android builds run perfectly fine, on iOS it results in the following runtime crash(es):

ArgumentOutOfRangeException: Value has to be >= 0. Parameter name: length

System.Array.Copy (System.Array sourceArray, System.Int32 sourceIndex, System.Array destinationArray, System.Int32 destinationIndex, System.Int32 length) (at <00000000000000000000000000000000>:0)
System.Array.Resize[T] (T[]& array, System.Int32 newSize) (at <00000000000000000000000000000000>:0)
Unity.Entities.Conversion.MultiList`2[T,I].Resize (Unity.Collections.NativeArray`1[System.Int32]& data, System.Int32 size) (at <00000000000000000000000000000000>:0)
Unity.Entities.Conversion.MultiList`2[T,I].Resize (Unity.Collections.NativeArray`1[System.Int32]& data, System.Int32 size) (at <00000000000000000000000000000000>:0)
Unity.Entities.Conversion.MultiList`2[T,I].Resize (Unity.Collections.NativeArray`1[System.Int32]& data, System.Int32 size) (at <00000000000000000000000000000000>:0)
Unity.Entities.Conversion.MultiList.CalcExpandCapacity (System.Int32 current, System.Int32& needed) (at <00000000000000000000000000000000>:0)
Game.Systems.Conversion.PrefabRegistryEntryAuthoring.Convert (Unity.Entities.Entity entity, Unity.Entities.EntityManager entityManager, GameObjectConversionSystem gameObjectConversionSystem) (at <00000000000000000000000000000000>:0)
Unity.Entities.Conversion.ConvertGameObjectToEntitySystem.Convert (UnityEngine.Transform transform, System.Collections.Generic.List`1[T] convertibles) (at <00000000000000000000000000000000>:0)
Unity.Entities.EntityQueryBuilder+F_C`1[T0].Invoke (T0 c0) (at <00000000000000000000000000000000>:0)
Unity.Entities.EntityManagerManagedComponentExtensions.SetComponentData[T] (Unity.Entities.EntityManager manager, Unity.Entities.Entity entity, T componentData) (at <00000000000000000000000000000000>:0)
Unity.Entities.Conversion.ConvertGameObjectToEntitySystem.OnUpdate () (at <00000000000000000000000000000000>:0)
Unity.Entities.ComponentSystem.Update () (at <00000000000000000000000000000000>:0)
Unity.Entities.ComponentSystemGroup.UpdateAllSystems () (at <00000000000000000000000000000000>:0)
Unity.Entities.ComponentSystem.Update () (at <00000000000000000000000000000000>:0)
Unity.Entities.GameObjectConversionUtility.Convert (Unity.Entities.World conversionWorld) (at <00000000000000000000000000000000>:0)
Unity.Entities.ConvertToEntitySystem.Convert () (at <00000000000000000000000000000000>:0)
Unity.Entities.ComponentSystem.Update () (at <00000000000000000000000000000000>:0)
Unity.Entities.ComponentSystemGroup.UpdateAllSystems () (at <00000000000000000000000000000000>:0)
Unity.Entities.ComponentSystem.Update () (at <00000000000000000000000000000000>:0)
UnityEngine.LowLevel.PlayerLoopSystem+UpdateFunction.Invoke () (at <00000000000000000000000000000000>:0)
Unity.Entities.Conversion.ConvertGameObjectToEntitySystem:Convert(Transform, List`1)
Unity.Entities.F_C`1:Invoke(T0)
Unity.Entities.EntityManagerManagedComponentExtensions:SetComponentData(EntityManager, Entity, T)
Unity.Entities.Conversion.ConvertGameObjectToEntitySystem:OnUpdate()
Unity.Entities.ComponentSystem:Update()
Unity.Entities.ComponentSystemGroup:UpdateAllSystems()
Unity.Entities.ComponentSystem:Update()
Unity.Entities.GameObjectConversionUtility:Convert(World)
Unity.Entities.ConvertToEntitySystem:Convert()
Unity.Entities.ComponentSystem:Update()
Unity.Entities.ComponentSystemGroup:UpdateAllSystems()
Unity.Entities.ComponentSystem:Update()
UnityEngine.LowLevel.UpdateFunction:Invoke()

Here’s another one: (Btw, mysteriously Facebook.Unity.MethodCall shows up at the top of this stack trace, but that’s possibly just due to various crash loggers hooking all over the place :hushed:)

IndexOutOfRangeException: Index was outside the bounds of the array.

Facebook.Unity.MethodCall`1[T].set_Parameters (Facebook.Unity.MethodArguments value) (at <00000000000000000000000000000000>:0)
Unity.Entities.Conversion.MultiList`2[T,I].Resize (Unity.Collections.NativeArray`1[System.Int32]& data, System.Int32 size) (at <00000000000000000000000000000000>:0)
Unity.Entities.Conversion.MultiList.CalcExpandCapacity (System.Int32 current, System.Int32& needed) (at <00000000000000000000000000000000>:0)
Unity.Entities.Conversion.MultiList.CalcExpandCapacity (System.Int32 current, System.Int32& needed) (at <00000000000000000000000000000000>:0)
Unity.Entities.Conversion.JournalingUnityLogger.LogException (System.Exception exception, UnityEngine.Object context) (at <00000000000000000000000000000000>:0)
Unity.Entities.ComponentSystemGroup.UpdateAllSystems () (at <00000000000000000000000000000000>:0)
Unity.Entities.ComponentSystem.Update () (at <00000000000000000000000000000000>:0)
Unity.Entities.GameObjectConversionUtility.Convert (Unity.Entities.World conversionWorld) (at <00000000000000000000000000000000>:0)
Unity.Entities.ConvertToEntitySystem.Convert () (at <00000000000000000000000000000000>:0)
Unity.Entities.ComponentSystem.Update () (at <00000000000000000000000000000000>:0)
Unity.Entities.ComponentSystemGroup.UpdateAllSystems () (at <00000000000000000000000000000000>:0)
Unity.Entities.ComponentSystem.Update () (at <00000000000000000000000000000000>:0)
UnityEngine.LowLevel.PlayerLoopSystem+UpdateFunction.Invoke () (at <00000000000000000000000000000000>:0)
Unity.Entities.ComponentSystemGroup:UpdateAllSystems()
Unity.Entities.ComponentSystem:Update()
UnityEngine.LowLevel.UpdateFunction:Invoke()

I have not yet worked on a MVP to reproduce this bug outside of my game, but I’m wondering if this is a known issue.

My package.json is as follows:

{
  "dependencies": {
    "com.e7.notch-solution": "git://github.com/5argon/NotchSolution.git",
    "com.google.external-dependency-manager": "1.2.163",
    "com.google.firebase.analytics": "7.0.2",
    "com.google.firebase.auth": "7.0.2",
    "com.google.firebase.crashlytics": "7.0.2",
    "com.google.firebase.installations": "7.0.2",
    "com.google.firebase.messaging": "7.0.2",
    "com.google.firebase.remote-config": "7.0.2",
    "com.unity.2d.sprite": "1.0.0",
    "com.unity.addressables": "1.16.15",
    "com.unity.analytics": "3.5.3",
    "com.unity.animation": "0.8.0-preview.4",
    "com.unity.device-simulator": "2.2.3-preview",
    "com.unity.dots.editor": "0.11.0-preview.3",
    "com.unity.entities": "0.16.0-preview.21",
    "com.unity.ide.rider": "3.0.3",
    "com.unity.inputsystem": "1.0.1",
    "com.unity.localization": "0.9.0-preview",
    "com.unity.mobile.notifications": "1.3.2",
    "com.unity.nuget.newtonsoft-json": "2.0.0",
    "com.unity.performance.profile-analyzer": "1.0.3",
    "com.unity.platforms.android": "0.9.0-preview.9",
    "com.unity.platforms.ios": "0.9.0-preview.9",
    "com.unity.platforms.macos": "0.9.0-preview.9",
    "com.unity.polybrush": "1.0.2",
    "com.unity.physics": "0.5.1-preview.2",
    "com.unity.probuilder": "4.4.0",
    "com.unity.progrids": "3.0.3-preview.6",
    "com.unity.properties": "1.3.0-preview",
    "com.unity.properties.ui": "1.6.0-preview",
    "com.unity.purchasing": "2.2.1",
    "com.unity.purchasing.udp": "2.1.4",
    "com.unity.quicksearch": "2.0.2",
    "com.unity.render-pipelines.universal": "9.0.0-preview.72",
    "com.unity.rendering.hybrid": "0.10.0-preview.21",
    "com.unity.serialization": "1.6.1-preview",
    "com.unity.test-framework": "1.1.19",
    "com.unity.test-framework.performance": "2.2.0-preview",
    "com.unity.timeline": "1.3.6",
    "com.unity.ugui": "1.0.0",
    "com.unity.uiextensions": "2.2.2",
    "com.unity.modules.ai": "1.0.0",
    "com.unity.modules.androidjni": "1.0.0",
    "com.unity.modules.animation": "1.0.0",
    "com.unity.modules.assetbundle": "1.0.0",
    "com.unity.modules.audio": "1.0.0",
    "com.unity.modules.cloth": "1.0.0",
    "com.unity.modules.director": "1.0.0",
    "com.unity.modules.imageconversion": "1.0.0",
    "com.unity.modules.imgui": "1.0.0",
    "com.unity.modules.jsonserialize": "1.0.0",
    "com.unity.modules.particlesystem": "1.0.0",
    "com.unity.modules.physics": "1.0.0",
    "com.unity.modules.physics2d": "1.0.0",
    "com.unity.modules.screencapture": "1.0.0",
    "com.unity.modules.terrain": "1.0.0",
    "com.unity.modules.terrainphysics": "1.0.0",
    "com.unity.modules.tilemap": "1.0.0",
    "com.unity.modules.ui": "1.0.0",
    "com.unity.modules.uielements": "1.0.0",
    "com.unity.modules.umbra": "1.0.0",
    "com.unity.modules.unityanalytics": "1.0.0",
    "com.unity.modules.unitywebrequest": "1.0.0",
    "com.unity.modules.unitywebrequestassetbundle": "1.0.0",
    "com.unity.modules.unitywebrequestaudio": "1.0.0",
    "com.unity.modules.unitywebrequesttexture": "1.0.0",
    "com.unity.modules.unitywebrequestwww": "1.0.0",
    "com.unity.modules.vehicles": "1.0.0",
    "com.unity.modules.video": "1.0.0",
    "com.unity.modules.vr": "1.0.0",
    "com.unity.modules.wind": "1.0.0",
    "com.unity.modules.xr": "1.0.0"
  },
  "scopedRegistries": [
    {
      "name": "Game Package Registry by Google",
      "url": "https://unityregistry-pa.googleapis.com",
      "scopes": [
        "com.google"
      ]
    },
    {
      "name": "npmjs",
      "url": "https://registry.npmjs.org/",
      "scopes": [
        "com.unity.uiextensions"
      ]
    }
  ]
}

I’m using Unity 2020.1.17f1, Xcode 12.2 (12B45b), iPhone11,8, iOS 14.0, arm64e,
if that matters.

The exact same IConvertGameObjectToEntity has worked on older entities package 0.11.2-preview.1 just fine on iOS. And as I mentioned it works just fine on Android and iOS.

Does anyone have an idea what’s going wrong here?

Thanks,
Nicolas

Could this be an IL2CPP build requesting generic API TryGetComponent problem? With code striping managed to remove the required function.
I was using this and it works on ios android and pc standalone.

   [DisallowMultipleComponent]
    public class HybridComponent : MonoBehaviour, IConvertGameObjectToEntity
    {
        [SerializeField, NaughtyAttributes.ReorderableList] protected List<UnityEngine.Component> Components = new List<Component>();

        public virtual bool IsNativeSupported(Component comp) =>
            comp is Transform ||
            comp is MeshRenderer ||
            comp is MeshFilter ||
            comp is SpriteRenderer ||
            comp is UnityEngine.VFX.VisualEffect ||
            comp is IConvertGameObjectToEntity ||
            comp is ConvertToEntity ||
            comp.GetType().Name.Contains("Authoring");

        protected virtual void Reset()
        {
            Components.Clear();
            foreach (var comp in gameObject.GetComponents<Component>())
            {
                if (IsNativeSupported(comp)) continue;
                else Components.Add(comp);
            }
        }

        private void OnValidate()
        {
            if (Components.Any(c => c is ParticleSystem) && Components.All(c => !(c is ParticleSystemRenderer)))
            {
                var renderer = GetComponent<ParticleSystemRenderer>();
                if (renderer != null) Components.Add(renderer);
                else Debug.LogError("ParticleSystem referenced but ParticleSystemRenderer is missing!");
            }
        }

        public void Convert(Entity entity, EntityManager dstManager, GameObjectConversionSystem conversionSystem)
        {
            foreach (var comp in Components)
            {
                if (!comp) continue;
                conversionSystem.AddHybridComponent(comp);
                if (comp is SkinnedMeshRenderer)
                {
                    var animator = transform.GetComponentInParent<Animator>();
                    var animatorEntity = conversionSystem.GetPrimaryEntity(animator);
                    dstManager.AddComponentObject(entity, new HybridSkinnedMeshHackSystem.TempAnimatorBind() { animator = animatorEntity });
                    conversionSystem.AddHybridComponent(animator);
                }
            }
        }
    }

I got it to crash with the XCode debugger attached:

Here are the relevant snapshots of the call stack:


continued…

… continuing

Hm, I don’t think so. When running from Xcode it occasionally works (maybe when the MultiList/Array stuff is seems to be doing internally for some reason doesn’t need to be resized??!?). So if it sometimes works, I’d assume it’s not a code stripping issue?! :face_with_spiral_eyes:

@Lieene-Guo btw, what Unity/Entities version are you using?

Here’s another one

Same as yours 0.16.0p21

1 Like

And another one:

RankException: Only single dimension arrays are supported here.
  at System.Array.Copy (System.Array sourceArray, System.Int32 sourceIndex, System.Array destinationArray, System.Int32 destinationIndex, System.Int32 length) [0x00000] in <00000000000000000000000000000000>:0
  at System.Array.Resize[T] (T[]& array, System.Int32 newSize) [0x00000] in <00000000000000000000000000000000>:0
  at Unity.Entities.Conversion.MultiList`2[T,I].Resize (Unity.Collections.NativeArray`1[System.Int32]& data, System.Int32 size) [0x00000] in <00000000000000000000000000000000>:0
  at Unity.Entities.Conversion.MultiList`2[T,I].Resize (Unity.Collections.NativeArray`1[System.Int32]& data, System.Int32 size) [0x00000] in <00000000000000000000000000000000>:0
  at Unity.Entities.Conversion.MultiList`2[T,I].Resize (Unity.Collections.NativeArray`1[System.Int32]& data, System.Int32 size) [0x00000] in <00000000000000000000000000000000>:0
  at Unity.Entities.Conversion.MultiList.CalcExpandCapacity (System.Int32 current, System.Int32& needed) [0x00000] in <00000000000000000000000000000000>:0
  at Game.Systems.Conversion.PrefabRegistryEntryAuthoring.Convert (Unity.Entities.Entity entity, Unity.Entities.EntityManager entityManager, GameObjectConversionSystem gameObjectConversionSystem) [0x00000] in <00000000000000000000000000000000>:0 
  at Unity.Entities.Conversion.ConvertGameObjectToEntitySystem.Convert (UnityEngine.Transform transform, System.Collections.Generic.List`1[T] convertibles) [0x00000] in <00000000000000000000000000000000>:0
  at Unity.Entities.EntityQueryBuilder+F_C`1[T0].Invoke (T0 c0) [0x00000] in <00000000000000000000000000000000>:0
  at Unity.Entities.EntityManagerManagedComponentExtensions.SetComponentData[T] (Unity.Entities.EntityManager manager, Unity.Entities.Entity entity, T componentData) [0x00000] in <00000000000000000000000000000000>:0
  at Unity.Entities.Conversion.ConvertGameObjectToEntitySystem.OnUpdate () [0x00000] in <00000000000000000000000000000000>:0
  at Unity.Entities.ComponentSystem.Update () [0x00000] in <00000000000000000000000000000000>:0
  at Unity.Entities.ComponentSystemGroup.UpdateAllSystems () [0x00000] in <00000000000000000000000000000000>:0
  at Unity.Entities.ComponentSystem.Update () [0x00000] in <00000000000000000000000000000000>:0
  at Unity.Entities.GameObjectConversionUtility.Convert (Unity.Entities.World conversionWorld) [0x00000] in <00000000000000000000000000000000>:0
  at Unity.Entities.ConvertToEntitySystem.Convert () [0x00000] in <00000000000000000000000000000000>:0
  at Unity.Entities.ComponentSystem.Update () [0x00000] in <00000000000000000000000000000000>:0
  at Unity.Entities.ComponentSystemGroup.UpdateAllSystems () [0x00000] in <00000000000000000000000000000000>:0
  at Unity.Entities.ComponentSystem.Update () [0x00000] in <00000000000000000000000000000000>:0
  at UnityEngine.LowLevel.PlayerLoopSystem+UpdateFunction.Invoke () [0x00000] in <00000000000000000000000000000000>:0
Unity.Entities.Conversion.ConvertGameObjectToEntitySystem:Convert(Transform, List`1)
Unity.Entities.F_C`1:Invoke(T0)
Unity.Entities.EntityManagerManagedComponentExtensions:SetComponentData(EntityManager, Entity, T)
Unity.Entities.Conversion.ConvertGameObjectToEntitySystem:OnUpdate()
Unity.Entities.ComponentSystem:Update()
Unity.Entities.ComponentSystemGroup:UpdateAllSystems()
Unity.Entities.ComponentSystem:Update()
Unity.Entities.GameObjectConversionUtility:Convert(World)
Unity.Entities.ConvertToEntitySystem:Convert()
Unity.Entities.ComponentSystem:Update()
Unity.Entities.ComponentSystemGroup:UpdateAllSystems()
Unity.Entities.ComponentSystem:Update()
UnityEngine.LowLevel.UpdateFunction:Invoke()

The weird thing is that the errors aren’t always quite the same, but very very similar. Almost feels like garbage data is passed down into the MultiList and it’s basically random what happens from there… :hushed::hushed::hushed:

I’m going to try a build that has all this Hybrid stuff disabled entirely and see how that goes. Wouldn’t be the first time Hybrid components are broken on one platform (back a few months ago it was Android only iirc)…

If you got SubScene working. You can try not to do and runtime conversion by exporting the Entity scene directly.
I also found some issues when converting on a mobile platform runtime with il2cpp.

Wow, hope it’s not a wild pointer not guarded by safetyHandle.

Yeah, that’s on editor-time pre-conversion of all my prefabs is on the todo list. But don’t want to mess with that before Christmas… :sweat_smile:

So I ust commented out the AddHybridComponent stuff for ParticleSystem/Renderer like so:
6648556--759376--upload_2020-12-22_0-7-16.jpg

and particlesystems are STILL working…

Oddly I need to keep TrailRenderer in there for the trails to show up, but it appears it’s not necessary anymore for ParticleSystems? Am I going crazy? Do you get the same behavior?

I just double checked the entities changelog and couldn’t find anything there about ParticleSystems being converted automatically and I’m 100% sure this used to be necessary previously :hushed::face_with_spiral_eyes::hushed:

Oh, yes that’s the new hybrid renderer update. I forget that.

1 Like

this is added to HybridEntitiesConversion

           Entities.ForEach((ParticleSystem ps, ParticleSystemRenderer ren) =>
            {
                AddHybridComponent(ps);
                AddHybridComponent(ren);
            });
1 Like

Yikes, makes me wonder if all my ParticleSystems are updating (or even rendering) twice rn… :face_with_spiral_eyes:

I’ll give it a shot tomorrow and see if that fixes things :roll_eyes:

Tried it with ParticleSystem stuff commented out (aka no double HybridComponent) and that doesn’t seem to make a difference. Now trying this completely without the system.

Another expression of the same bug:

ArrayTypeMismatchException: Attempted to access an element as a type incompatible with the array.

Unity.Entities.Conversion.MultiList`2[T,I].Resize (Unity.Collections.NativeArray`1[System.Int32]& data, System.Int32 size) (at <00000000000000000000000000000000>:0)
...

Posting all these for visibility, jic someone else runs into the same issue :frowning:

So I just removed my IConvertGameObjectToEntity entirely and it’s still crashing (slightly less often) in the general ConvertToEntitySystem (other keywords: GameObjectConversionMappingSystem CreateCompanionGameObjects, GameObjectConversionUtility) call stack:



You might have had the right intuition here.

If I’m reading the crash stack trace right, it’s crashing here:

foreach (var component in gameObject.GetComponents<UnityComponent>())
{
    if (component == null)
        continue;
    var type = component.GetType();
    if (!components.Contains(type)) <-- crash inside of here

6651553--759880--upload_2020-12-22_16-28-9.jpg

Something must be wrong with the type info :hushed:

I was going to try to remove stripping but… I guess that’s not possible with IL2CPP… :(:(:frowning:

6651553--759883--upload_2020-12-22_16-36-32.png