Search Unity

Help Please

Discussion in 'Entity Component System' started by RoughSpaghetti3211, Jun 3, 2020.

  1. RoughSpaghetti3211

    RoughSpaghetti3211

    Joined:
    Aug 11, 2015
    Posts:
    1,705
    I have no idea why this is not safe, seems so simple what am I missing here

    InvalidOperationException: The previously scheduled job CreateTileEntitySystem:<>c__DisplayClass_CreateTileEntitySystem reads from the NativeArray <>c__DisplayClass_CreateTileEntitySystem.safety. You must call JobHandle.Complete() on the job CreateTileEntitySystem:<>c__DisplayClass_CreateTileEntitySystem, before you can deallocate the NativeArray safely.
    Unity.Collections.LowLevel.Unsafe.AtomicSafetyHandle.CheckDeallocateAndThrow (Unity.Collections.LowLevel.Unsafe.AtomicSafetyHandle handle) <0x174aae3d0 + 0x00052> in <8ffa1ce5ca714d4bbf5ca6c83220b963>:0


    Code (CSharp):
    1.  
    2.  
    3. namespace Universe.Planet.Systems
    4. {
    5.     [UpdateInGroup(typeof(SimulationSystemGroup))]
    6.     public class CreateTileEntitySystem : SystemBase
    7.     {
    8.         BeginInitializationEntityCommandBufferSystem EntityCommandBufferSystem;
    9.  
    10.        
    11.         protected override void OnCreate()
    12.         {
    13.             base.OnCreate();
    14.            
    15.             EntityCommandBufferSystem = World.GetOrCreateSystem<BeginInitializationEntityCommandBufferSystem>();
    16.         }
    17.  
    18.         protected override void OnUpdate()
    19.         {
    20.             var commandBuffer = EntityCommandBufferSystem.CreateCommandBuffer().ToConcurrent();
    21.  
    22.             Entities
    23.                 .WithName("CreateTileEntitySystem")
    24.                 .WithChangeFilter<PlanetBuildComponent>()
    25.                 .WithBurst(FloatMode.Default, FloatPrecision.Standard, true)
    26.                 .ForEach((Entity e, int entityInQueryIndex, in PlanetBuildComponent b ) =>
    27.                 {
    28.  
    29.                     for (var i = 0; i < b.VertexCount; i++)
    30.                     {
    31.  
    32.                     }
    33.            
    34.                 }).ScheduleParallel(Dependency);
    35.            
    36.             EntityCommandBufferSystem.AddJobHandleForProducer(Dependency);
    37.         }
    38.     }
    39. }
    40.  
     
  2. brunocoimbra

    brunocoimbra

    Joined:
    Sep 2, 2015
    Posts:
    679
    You are missing to assign the Dependency property back
    Code (CSharp):
    1.  
    2. namespace Universe.Planet.Systems
    3. {
    4.     [UpdateInGroup(typeof(SimulationSystemGroup))]
    5.     public class CreateTileEntitySystem : SystemBase
    6.     {
    7.         BeginInitializationEntityCommandBufferSystem EntityCommandBufferSystem;
    8.  
    9.        
    10.         protected override void OnCreate()
    11.         {
    12.             base.OnCreate();
    13.            
    14.             EntityCommandBufferSystem = World.GetOrCreateSystem<BeginInitializationEntityCommandBufferSystem>();
    15.         }
    16.  
    17.         protected override void OnUpdate()
    18.         {
    19.             var commandBuffer = EntityCommandBufferSystem.CreateCommandBuffer().ToConcurrent();
    20.  
    21.             // here
    22.             Dependency = Entities
    23.                 .WithName("CreateTileEntitySystem")
    24.                 .WithChangeFilter<PlanetBuildComponent>()
    25.                 .WithBurst(FloatMode.Default, FloatPrecision.Standard, true)
    26.                 .ForEach((Entity e, int entityInQueryIndex, in PlanetBuildComponent b ) =>
    27.                 {
    28.  
    29.                     for (var i = 0; i < b.VertexCount; i++)
    30.                     {
    31.  
    32.                     }
    33.            
    34.                 }).ScheduleParallel(Dependency);
    35.            
    36.             EntityCommandBufferSystem.AddJobHandleForProducer(Dependency);
    37.         }
    38.     }
    39. }
    40.  
     
  3. RoughSpaghetti3211

    RoughSpaghetti3211

    Joined:
    Aug 11, 2015
    Posts:
    1,705
    So much cussing on this end .. thank you
     
    brunocoimbra likes this.
  4. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    3,759
    As was pointed out you aren't handling the dependency, but the issue is more you're passing the dependency in.

    Instead of

    Dependency = Entities.ForEach(() => {}).ScheduleParallel(Dependency);


    You can just do

    Entities.ForEach(() => {}).ScheduleParallel();


    The problem is when you try and mix