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. Dismiss Notice

Burst Error when using .asmdef

Discussion in 'Burst' started by Ziboo, Apr 16, 2020.

  1. Ziboo

    Ziboo

    Joined:
    Aug 30, 2011
    Posts:
    356
    Hello,

    My code is running fine:
    • without .asmdef and Burst enabled
    • with .asmdef and Burst disabled
    My code give me errors:
    • with .asmdef and Burst enabled
    Error :
    Code (CSharp):
    1. System.ArgumentException: Unknown Type:`{0}` All ComponentType must be known at compile time. For generic components, each concrete type must be registered with [RegisterGenericComponentType].
    2. Thrown from job: Assets._Project.Scripts.ECS.Factory.Conveyors.ConveyorPushSystemJob.Assets._Project.Scripts.ECS.Factory.Conveyors.<>c__DisplayClass_ConveyorPush
    3. This Exception was thrown from a job compiled with Burst, which has limited exception support. Turn off burst (Jobs -> Burst -> Enable Compilation) to inspect full exceptions & stacktraces.
    And my .asmdef:
    upload_2020-4-16_11-11-20.png

    Any clues ?

    Thanks !
     
  2. Ziboo

    Ziboo

    Joined:
    Aug 30, 2011
    Posts:
    356
    Some more info with the same setup.

    I don't have an error if I check "Jobs > Burst > Native Debug Mode Compilation"

    And sometime I have also this error:

    Code (CSharp):
    1. ArgumentException: System.ArgumentException: A component with type:{0} has not been added to the entity.
    2. Thrown from job: Unity.Entities.EntityCommandBuffer.PlaybackChainChunkWrapper
    3. This Exception was thrown from a function compiled with Burst, which has limited exception support. Turn off burst (Jobs -> Burst -> Enable Compilation) to inspect full exceptions & stacktraces.
    4. EntityCommandBuffer was recorded in Assets._Project.Scripts.ECS.Factory.Conveyors.ConveyorPushSystemJob and played back in Assets._Project.Scripts.ECS.Factory.FactoryCommandBuffer.
    5.   at (wrapper managed-to-native) System.Object.wrapper_native_000001DBB68901C0(EntityDataAccess*,Unity.Collections.LowLevel.Unsafe.UnsafeList*,Unity.Entities.EntityComponentStore/ArchetypeChanges&,Unity.Entities.ECBSharedPlaybackState&,Unity.Entities.ECBChainPlaybackState*,int,int,bool,Unity.Entities.PlaybackPolicy)
    6.   at (wrapper delegate-invoke) <Module>.invoke_void_EntityDataAccess*_UnsafeList*_EntityComponentStore/ArchetypeChanges&_ECBSharedPlaybackState&_ECBChainPlaybackState*_int_int_bool_PlaybackPolicy(EntityDataAccess*,Unity.Collections.LowLevel.Unsafe.UnsafeList*,Unity.Entities.EntityComponentStore/ArchetypeChanges&,Unity.Entities.ECBSharedPlaybackState&,Unity.Entities.ECBChainPlaybackState*,int,int,bool,Unity.Entities.PlaybackPolicy)
    7.   at Unity.Entities.EntityCommandBuffer.PlaybackChain (EntityDataAccess mgr, Unity.Collections.LowLevel.Unsafe.UnsafeList* managedReferenceIndexRemovalCount, Unity.Entities.EntityComponentStore+ArchetypeChanges& archetypeChanges, Unity.Entities.ECBSharedPlaybackState& playbackState, Unity.Entities.ECBChainPlaybackState* chainStates, System.Int32 currentChain, System.Int32 nextChain, System.Boolean isFirstPlayback, Unity.Entities.PlaybackPolicy playbackPolicy) [0x000ca] in D:\Projects\Unity2020\RobotWar\Unity\Library\PackageCache\com.unity.entities@0.8.0-preview.8\Unity.Entities\EntityCommandBuffer.cs:1494
    8.   at Unity.Entities.EntityCommandBuffer.PlaybackInternal (EntityDataAccess mgr) [0x00306] in D:\Projects\Unity2020\RobotWar\Unity\Library\PackageCache\com.unity.entities@0.8.0-preview.8\Unity.Entities\EntityCommandBuffer.cs:1325
    9.   at Unity.Entities.EntityCommandBuffer.Playback (Unity.Entities.EntityManager mgr) [0x0000e] in D:\Projects\Unity2020\RobotWar\Unity\Library\PackageCache\com.unity.entities@0.8.0-preview.8\Unity.Entities\EntityCommandBuffer.cs:1189
    10.   at Unity.Entities.EntityCommandBufferSystem.FlushPendingBuffers (System.Boolean playBack) [0x0004b] in D:\Projects\Unity2020\RobotWar\Unity\Library\PackageCache\com.unity.entities@0.8.0-preview.8\Unity.Entities\EntityCommandBufferSystem.cs:220
    11.  
     
  3. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    3,626
    Show the code for your Conveyors<> job in ConveyorPushSystemJob.

    Looks like you're doing something not supported with generics.
     
  4. Ziboo

    Ziboo

    Joined:
    Aug 30, 2011
    Posts:
    356
    Here is the script:
    Code (CSharp):
    1. using Assets._Project.Scripts.ECS.Factory.Grid;
    2. using Unity.Entities;
    3.  
    4. namespace Assets._Project.Scripts.ECS.Factory.Conveyors
    5. {
    6.     [UpdateInGroup(typeof(FactoryEndGroup))]
    7.     public class ConveyorPushSystemJob : SystemBase
    8.     {
    9.         private FactoryCommandBuffer bufferSystem;
    10.         private int offsetIndex;
    11.  
    12.         protected override void OnCreate()
    13.         {
    14.             this.bufferSystem = this.World.GetExistingSystem<FactoryEndGroup>().EndBufferSystem;
    15.         }
    16.  
    17.  
    18.         protected override void OnUpdate()
    19.         {
    20.             var buffer = this.bufferSystem.CreateCommandBuffer().ToConcurrent();
    21.             var neighbours = this.GetBufferFromEntity<GridNeighbours>(true);
    22.             var offset = this.offsetIndex;
    23.  
    24.             Entity GetNeighbour(Entity currentEntity, int jobIndex)
    25.             {
    26.                 var neighboursBuffers = neighbours[currentEntity];
    27.  
    28.                 // check 4 neighbours East - North - West - South
    29.                 for (var i = 0; i < 4; i++)
    30.                 {
    31.                     var index = (i + offset) % 4;
    32.  
    33.                     var nEntity = neighboursBuffers[index].Entity;
    34.  
    35.                     //Check out of bound
    36.                     if (nEntity == Entity.Null) continue;
    37.  
    38.                     var gns = this.GetComponent<GrideNodeStatus>(nEntity);
    39.  
    40.                     if (gns.Status == GridNodeStatuses.Locked
    41.                         || gns.Status == GridNodeStatuses.Working
    42.                     )
    43.                         continue;
    44.  
    45.                     //Check if there is a pusher
    46.  
    47.  
    48.                     if (this.HasComponent<ConveyorPusher>(nEntity) == false) continue;
    49.  
    50.                     var pusher = this.GetComponent<ConveyorPusher>(nEntity);
    51.  
    52.                     if (pusher.IsDisable) continue;
    53.  
    54.                     //Check if there is a movable
    55.  
    56.                     var movable = this.GetComponent<GridNode>(nEntity).EntityOnTop;
    57.                     if (movable == Entity.Null) continue;
    58.  
    59.  
    60.                     //Check if the pusher will push to the current index
    61.                     if ((int) pusher.Direction.Inverse() == index)
    62.                     {
    63.                         buffer.SetComponent(jobIndex, nEntity, new GridNode());
    64.  
    65.                         buffer.AddComponent(jobIndex, movable, new ConveyerMoveEntity
    66.                         {
    67.                             FromEntity = nEntity,
    68.                             TargetEntity = currentEntity,
    69.                             Target = this.GetComponent<GridCoord>(currentEntity)
    70.                         });
    71.  
    72.  
    73.                         buffer.SetComponent(jobIndex, currentEntity, new GrideNodeStatus
    74.                         {
    75.                             Status = GridNodeStatuses.Locked
    76.                         });
    77.  
    78.  
    79.                         return nEntity;
    80.                     }
    81.                 }
    82.  
    83.                 return Entity.Null;
    84.             }
    85.  
    86.  
    87.             this.Entities
    88.                 .WithName("ConveyorPush")
    89.                 .WithReadOnly(neighbours)
    90.                 .WithAll<ConveyerReceiver>()
    91.                 .ForEach((Entity entity, int entityInQueryIndex, in GridNode gridNode) =>
    92.                 {
    93.                     if (gridNode.EntityOnTop != Entity.Null) return;
    94.  
    95.                     var gns = this.GetComponent<GrideNodeStatus>(entity);
    96.  
    97.                     //TODO Other Statuses ?
    98.                     if (gns.Status == GridNodeStatuses.Working
    99.                         || gns.Status == GridNodeStatuses.Locked)
    100.                         return;
    101.  
    102.                     var jobIndex = entityInQueryIndex;
    103.  
    104.                     var currentEntity = entity;
    105.  
    106.                     while (currentEntity != Entity.Null) currentEntity = GetNeighbour(currentEntity, jobIndex);
    107.                 }).ScheduleParallel();
    108.  
    109.             this.bufferSystem.AddJobHandleForProducer(this.Dependency);
    110.  
    111.             this.offsetIndex++;
    112.         }
    113.     }
    114. }
    And the compiled one:
    Code (CSharp):
    1.  
    2. using Assets._Project.Scripts.ECS.Factory.Grid;
    3. using System.Runtime.CompilerServices;
    4. using Unity.Burst;
    5. using Unity.Collections;
    6. using Unity.Collections.LowLevel.Unsafe;
    7. using Unity.Entities;
    8. using Unity.Entities.CodeGeneratedJobForEach;
    9. using Unity.Jobs;
    10.  
    11. namespace Assets._Project.Scripts.ECS.Factory.Conveyors
    12. {
    13.     [UpdateInGroup(typeof(FactoryEndGroup))]
    14.     public class ConveyorPushSystemJob : SystemBase
    15.     {
    16.         [Unity.Entities.DOTSCompilerGenerated]
    17.         [BurstCompile]
    18.         [NoAlias]
    19.         private struct <>c__DisplayClass_ConveyorPush : IJobChunk
    20.         {
    21.             private struct LambdaParameterValueProviders
    22.             {
    23.                 [NoAlias]
    24.                 public struct Runtimes
    25.                 {
    26.                     [NoAlias]
    27.                     public LambdaParameterValueProvider_Entity.Runtime runtime_entity;
    28.  
    29.                     [NoAlias]
    30.                     public LambdaParameterValueProvider_EntityInQueryIndex.Runtime runtime_entityInQueryIndex;
    31.  
    32.                     [NoAlias]
    33.                     public LambdaParameterValueProvider_IComponentData<GridNode>.Runtime runtime_gridNode;
    34.                 }
    35.  
    36.                 [ReadOnly]
    37.                 [NoAlias]
    38.                 private LambdaParameterValueProvider_Entity forParameter_entity;
    39.  
    40.                 [ReadOnly]
    41.                 [NoAlias]
    42.                 private LambdaParameterValueProvider_EntityInQueryIndex forParameter_entityInQueryIndex;
    43.  
    44.                 [ReadOnly]
    45.                 [NoAlias]
    46.                 private LambdaParameterValueProvider_IComponentData<GridNode> forParameter_gridNode;
    47.  
    48.                 public void ScheduleTimeInitialize(ConveyorPushSystemJob componentSystem)
    49.                 {
    50.                     forParameter_entity.ScheduleTimeInitialize(componentSystem, isReadOnly: true);
    51.                     forParameter_entityInQueryIndex.ScheduleTimeInitialize(componentSystem, isReadOnly: true);
    52.                     forParameter_gridNode.ScheduleTimeInitialize(componentSystem, isReadOnly: true);
    53.                 }
    54.  
    55.                 public Runtimes PrepareToExecuteOnEntitiesInMethod(ref ArchetypeChunk p0, int p1, int p2)
    56.                 {
    57.                     Runtimes result = default(Runtimes);
    58.                     result.runtime_entity = forParameter_entity.PrepareToExecuteOnEntitiesIn(ref p0);
    59.                     result.runtime_entityInQueryIndex = forParameter_entityInQueryIndex.PrepareToExecuteOnEntitiesIn(ref p0, p1, p2);
    60.                     result.runtime_gridNode = forParameter_gridNode.PrepareToExecuteOnEntitiesIn(ref p0);
    61.                     return result;
    62.                 }
    63.             }
    64.  
    65.             [ReadOnly]
    66.             public BufferFromEntity<GridNeighbours> neighbours;
    67.  
    68.             public int offset;
    69.  
    70.             public EntityCommandBuffer.Concurrent buffer;
    71.  
    72.             [NoAlias]
    73.             [ReadOnly]
    74.             private ComponentDataFromEntity<GrideNodeStatus> _ComponentDataFromEntity_GrideNodeStatus_0;
    75.  
    76.             [NoAlias]
    77.             [ReadOnly]
    78.             private ComponentDataFromEntity<ConveyorPusher> _ComponentDataFromEntity_ConveyorPusher_1;
    79.  
    80.             [NoAlias]
    81.             [ReadOnly]
    82.             private ComponentDataFromEntity<GridNode> _ComponentDataFromEntity_GridNode_2;
    83.  
    84.             [NoAlias]
    85.             [ReadOnly]
    86.             private ComponentDataFromEntity<GridCoord> _ComponentDataFromEntity_GridCoord_3;
    87.  
    88.             private LambdaParameterValueProviders _lambdaParameterValueProviders;
    89.  
    90.             [NativeDisableUnsafePtrRestriction]
    91.             private unsafe LambdaParameterValueProviders.Runtimes* _runtimes;
    92.  
    93.             public void OriginalLambdaBody(Entity entity, int entityInQueryIndex, in GridNode gridNode)
    94.             {
    95.                 if (gridNode.EntityOnTop != Entity.Null)
    96.                 {
    97.                     return;
    98.                 }
    99.                 GrideNodeStatus grideNodeStatus = _ComponentDataFromEntity_GrideNodeStatus_0[entity];
    100.                 if (grideNodeStatus.Status != GridNodeStatuses.Working && grideNodeStatus.Status != GridNodeStatuses.Locked)
    101.                 {
    102.                     Entity entity2 = entity;
    103.                     while (entity2 != Entity.Null)
    104.                     {
    105.                         entity2 = <OnUpdate>g__GetNeighbour|0(entity2, entityInQueryIndex);
    106.                     }
    107.                 }
    108.             }
    109.  
    110.             public Entity <OnUpdate>g__GetNeighbour|0(Entity currentEntity, int jobIndex)
    111.             {
    112.                 DynamicBuffer<GridNeighbours> dynamicBuffer = neighbours[currentEntity];
    113.                 for (int i = 0; i < 4; i++)
    114.                 {
    115.                     int num = (i + offset) % 4;
    116.                     Entity entity = dynamicBuffer[num].Entity;
    117.                     if (entity == Entity.Null)
    118.                     {
    119.                         continue;
    120.                     }
    121.                     GrideNodeStatus grideNodeStatus = _ComponentDataFromEntity_GrideNodeStatus_0[entity];
    122.                     if (grideNodeStatus.Status == GridNodeStatuses.Locked || grideNodeStatus.Status == GridNodeStatuses.Working || !_ComponentDataFromEntity_ConveyorPusher_1.HasComponent(entity))
    123.                     {
    124.                         continue;
    125.                     }
    126.                     ConveyorPusher conveyorPusher = _ComponentDataFromEntity_ConveyorPusher_1[entity];
    127.                     if (!conveyorPusher.IsDisable)
    128.                     {
    129.                         Entity entityOnTop = _ComponentDataFromEntity_GridNode_2[entity].EntityOnTop;
    130.                         if (!(entityOnTop == Entity.Null) && conveyorPusher.Direction.Inverse() == (Directions)num)
    131.                         {
    132.                             buffer.SetComponent(jobIndex, entity, default(GridNode));
    133.                             buffer.AddComponent(jobIndex, entityOnTop, new ConveyerMoveEntity
    134.                             {
    135.                                 FromEntity = entity,
    136.                                 TargetEntity = currentEntity,
    137.                                 Target = _ComponentDataFromEntity_GridCoord_3[currentEntity]
    138.                             });
    139.                             buffer.SetComponent(jobIndex, currentEntity, new GrideNodeStatus
    140.                             {
    141.                                 Status = GridNodeStatuses.Locked
    142.                             });
    143.                             return entity;
    144.                         }
    145.                     }
    146.                 }
    147.                 return Entity.Null;
    148.             }
    149.  
    150.             public void ReadFromDisplayClass(ref <>c__DisplayClass3_0 displayClass)
    151.             {
    152.                 neighbours = displayClass.neighbours;
    153.                 offset = displayClass.offset;
    154.                 buffer = displayClass.buffer;
    155.             }
    156.  
    157.             public unsafe void Execute(ArchetypeChunk chunk, int chunkIndex, int firstEntityIndex)
    158.             {
    159.                 LambdaParameterValueProviders.Runtimes runtimes = _lambdaParameterValueProviders.PrepareToExecuteOnEntitiesInMethod(ref chunk, chunkIndex, firstEntityIndex);
    160.                 _runtimes = &runtimes;
    161.                 IterateEntities(ref chunk, ref *_runtimes);
    162.             }
    163.  
    164.             [MethodImpl(MethodImplOptions.NoInlining)]
    165.             public void IterateEntities(ref ArchetypeChunk chunk, [NoAlias] ref LambdaParameterValueProviders.Runtimes runtimes)
    166.             {
    167.                 int count = chunk.Count;
    168.                 for (int i = 0; i < count; i++)
    169.                 {
    170.                     this.OriginalLambdaBody(runtimes.runtime_entity.For(i), runtimes.runtime_entityInQueryIndex.For(i), ref runtimes.runtime_gridNode.For(i));
    171.                 }
    172.             }
    173.  
    174.             public void ScheduleTimeInitialize(ConveyorPushSystemJob componentSystem, ref <>c__DisplayClass3_0 displayClass)
    175.             {
    176.                 _lambdaParameterValueProviders.ScheduleTimeInitialize(componentSystem);
    177.                 ReadFromDisplayClass(ref displayClass);
    178.                 _ComponentDataFromEntity_GrideNodeStatus_0 = componentSystem.GetComponentDataFromEntity<GrideNodeStatus>(isReadOnly: true);
    179.                 _ComponentDataFromEntity_ConveyorPusher_1 = componentSystem.GetComponentDataFromEntity<ConveyorPusher>(isReadOnly: true);
    180.                 _ComponentDataFromEntity_GridNode_2 = componentSystem.GetComponentDataFromEntity<GridNode>(isReadOnly: true);
    181.                 _ComponentDataFromEntity_GridCoord_3 = componentSystem.GetComponentDataFromEntity<GridCoord>(isReadOnly: true);
    182.             }
    183.         }
    184.  
    185.         private FactoryCommandBuffer bufferSystem;
    186.  
    187.         private int offsetIndex;
    188.  
    189.         private EntityQuery <>ConveyorPush_entityQuery;
    190.  
    191.         protected override void OnCreate()
    192.         {
    193.             bufferSystem = base.World.GetExistingSystem<FactoryEndGroup>().EndBufferSystem;
    194.         }
    195.  
    196.         protected override void OnUpdate()
    197.         {
    198.             <>c__DisplayClass3_0 displayClass = default(<>c__DisplayClass3_0);
    199.             displayClass.<>4__this = this;
    200.             displayClass.buffer = bufferSystem.CreateCommandBuffer().ToConcurrent();
    201.             displayClass.neighbours = GetBufferFromEntity<GridNeighbours>(isReadOnly: true);
    202.             displayClass.offset = offsetIndex;
    203.             ForEachLambdaJobDescription entity = base.Entities;
    204.             JobHandle dependency = base.Dependency;
    205.             <>c__DisplayClass_ConveyorPush jobData = default(<>c__DisplayClass_ConveyorPush);
    206.             jobData.ScheduleTimeInitialize(this, ref displayClass);
    207.             dependency = (base.Dependency = jobData.ScheduleParallel(<>ConveyorPush_entityQuery, dependency));
    208.             bufferSystem.AddJobHandleForProducer(base.Dependency);
    209.             offsetIndex++;
    210.         }
    211.  
    212.         protected internal override void OnCreateForCompiler()
    213.         {
    214.             base.OnCreateForCompiler();
    215.             <>ConveyorPush_entityQuery = <>GetEntityQuery_ForConveyorPush_From(this);
    216.         }
    217.  
    218.         public static EntityQuery <>GetEntityQuery_ForConveyorPush_From(ComponentSystemBase componentSystem)
    219.         {
    220.             EntityQueryDesc[] array = new EntityQueryDesc[1];
    221.             (array[0] = new EntityQueryDesc()).All = new ComponentType[2]
    222.             {
    223.                 ComponentType.ReadOnly<ConveyerReceiver>(),
    224.                 ComponentType.ReadOnly<GridNode>()
    225.             };
    226.             return componentSystem.GetEntityQuery(array);
    227.         }
    228.     }
    229. }
    230.  
    231.  
    Thanks a lot @tertle , I appreciate it
     
    Last edited: Apr 17, 2020
  5. jaydenm

    jaydenm

    Joined:
    Nov 16, 2018
    Posts:
    11
    @Ziboo Did you ever sort out this issue? I'm also hitting it when trying to use .asmdef's with Burst.