Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Join us on March 30, 2023, between 5 am & 1 pm EST, in the Performance Profiling Dev Blitz Day 2023 - Q&A forum and Discord where you can connect with our teams behind the Memory and CPU Profilers.
    Dismiss Notice

Question Calling ArchetypeChunk.GetNativeArray() with generic type throws exception in builds

Discussion in 'Project Tiny' started by NagaChiang, Dec 9, 2020.

  1. NagaChiang

    NagaChiang

    Joined:
    Sep 17, 2020
    Posts:
    13
    The call stack in wasm build looked like:
    Code (CSharp):
    1. il2cpp::os::CrashHelpers::CrashImpl()
    2. il2cpp::os::CrashHelpers::Crash()
    3. tiny::vm::Exception::Raise(char const*)
    4. tiny::vm::Exception::Raise(Il2CppException*)
    5. Unity.Entities.ArchetypeChunk.GetNativeArray<TestComponent>(Unity.Entities.ArchetypeChunk* this, Unity.Entities.ComponentTypeHandle`1<TestComponent> chunkComponentTypeHandle)_1A2F49CFDE7818D7
    6. GenericJob_Execute_m5A535D7AEC1C09F2265FE73601EA3F293114A3D1
    7. ...
    Here is the minimum code I could find to reproduce:
    Code (CSharp):
    1. using Unity.Burst;
    2. using Unity.Collections;
    3. using Unity.Entities;
    4. using Unity.Mathematics;
    5.  
    6. public class ApplySystem : SystemBase
    7. {
    8.     protected override void OnUpdate()
    9.     {
    10.         Entities.ForEach((in TestComponent test) => { }).ScheduleParallel();
    11.     }
    12. }
    13.  
    14. public class GenericSystem<T> : SystemBase
    15.     where T : struct, IComponentData
    16. {
    17.     [BurstCompile]
    18.     private struct GenericJob : IJobChunk
    19.     {
    20.         [ReadOnly] public ComponentTypeHandle<T> GenericType;
    21.  
    22.         public void Execute(ArchetypeChunk chunk, int chunkIndex, int firstEntityIndex)
    23.         {
    24.             NativeArray<T> generics = chunk.GetNativeArray(GenericType);
    25.         }
    26.     }
    27.  
    28.     private EntityQuery Query;
    29.  
    30.     protected override void OnCreate()
    31.     {
    32.         EntityManager.CreateEntity(ComponentType.ReadOnly<T>());
    33.         Query = GetEntityQuery(ComponentType.ReadOnly<T>());
    34.     }
    35.  
    36.     protected override void OnUpdate()
    37.     {
    38.         GenericJob job = new GenericJob
    39.         {
    40.             GenericType = GetComponentTypeHandle<T>(true),
    41.         };
    42.  
    43.         job.Run(Query);
    44.     }
    45. }
    46.  
    47. public class TestSystem : GenericSystem<TestComponent> {}
    48.  
    49. public struct TestComponent : IComponentData
    50. {
    51.     public float3 Value;
    52. }
    I'm using Unity 2020.1.12f1 and Tiny 0.31.0. This exception only happened in builds. I didn't know where the log of windows builds is, but it crashed.