Help Please

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

namespace Universe.Planet.Systems
{
    [UpdateInGroup(typeof(SimulationSystemGroup))]
    public class CreateTileEntitySystem : SystemBase
    {
        BeginInitializationEntityCommandBufferSystem EntityCommandBufferSystem;

        
        protected override void OnCreate()
        {
            base.OnCreate();
            
            EntityCommandBufferSystem = World.GetOrCreateSystem<BeginInitializationEntityCommandBufferSystem>();
        }

        protected override void OnUpdate()
        {
            var commandBuffer = EntityCommandBufferSystem.CreateCommandBuffer().ToConcurrent();

            Entities
                .WithName("CreateTileEntitySystem")
                .WithChangeFilter<PlanetBuildComponent>()
                .WithBurst(FloatMode.Default, FloatPrecision.Standard, true)
                .ForEach((Entity e, int entityInQueryIndex, in PlanetBuildComponent b ) =>
                {

                    for (var i = 0; i < b.VertexCount; i++)
                    {

                    }
            
                }).ScheduleParallel(Dependency);
            
            EntityCommandBufferSystem.AddJobHandleForProducer(Dependency);
        }
    }
}

You are missing to assign the Dependency property back

namespace Universe.Planet.Systems
{
    [UpdateInGroup(typeof(SimulationSystemGroup))]
    public class CreateTileEntitySystem : SystemBase
    {
        BeginInitializationEntityCommandBufferSystem EntityCommandBufferSystem;

        
        protected override void OnCreate()
        {
            base.OnCreate();
            
            EntityCommandBufferSystem = World.GetOrCreateSystem<BeginInitializationEntityCommandBufferSystem>();
        }

        protected override void OnUpdate()
        {
            var commandBuffer = EntityCommandBufferSystem.CreateCommandBuffer().ToConcurrent();

            // here
            Dependency = Entities
                .WithName("CreateTileEntitySystem")
                .WithChangeFilter<PlanetBuildComponent>()
                .WithBurst(FloatMode.Default, FloatPrecision.Standard, true)
                .ForEach((Entity e, int entityInQueryIndex, in PlanetBuildComponent b ) =>
                {

                    for (var i = 0; i < b.VertexCount; i++)
                    {

                    }
            
                }).ScheduleParallel(Dependency);
            
            EntityCommandBufferSystem.AddJobHandleForProducer(Dependency);
        }
    }
}

So much cussing on this end … thank you

1 Like

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

5 Likes