Skip to content

SimpleCullingJob Throw IndexOutOfRangeException When Destroying Lod Entities from ecb #10

Description

@DANaini13

When I use EntityCommandBuffer to Destory the Parent and LOD entities, It cause the error as following:

IndexOutOfRangeException: Index 33 is out of range of '33' Length.
Unity.Collections.NativeArray`1[T].FailOutOfRangeError (System.Int32 index) (at <3631fb7a903940d29845b8847b40e18e>:0)
Unity.Collections.NativeArray`1[T].CheckElementReadAccess (System.Int32 index) (at <3631fb7a903940d29845b8847b40e18e>:0)
Unity.Collections.NativeArray`1[T].get_Item (System.Int32 index) (at <3631fb7a903940d29845b8847b40e18e>:0)
Unity.Rendering.SimpleCullingJob.Execute (Unity.Entities.ArchetypeChunk archetypeChunk, System.Int32 chunkIndex, System.Int32 firstEntityIndex) (at Library/PackageCache/com.unity.rendering.hybrid@0.10.0-preview.21/Unity.Rendering.Hybrid/HybridV2Culling.cs:344)
Unity.Entities.JobChunkExtensions+JobChunkProducer`1[T].ExecuteInternal (Unity.Entities.JobChunkExtensions+JobChunkWrapper`1[T]& jobWrapper, System.IntPtr bufferRangePatchData, Unity.Jobs.LowLevel.Unsafe.JobRanges& ranges, System.Int32 jobIndex) (at Library/PackageCache/com.unity.entities@0.16.0-preview.21/Unity.Entities/IJobChunk.cs:370)
Unity.Entities.JobChunkExtensions+JobChunkProducer`1[T].Execute (Unity.Entities.JobChunkExtensions+JobChunkWrapper`1[T]& jobWrapper, System.IntPtr additionalPtr, System.IntPtr bufferRangePatchData, Unity.Jobs.LowLevel.Unsafe.JobRanges& ranges, System.Int32 jobIndex) (at Library/PackageCache/com.unity.entities@0.16.0-preview.21/Unity.Entities/IJobChunk.cs:337)

My code is like following:

var ecb = _ecbs.CreateCommandBuffer().AsParallelWriter();
var pos = new Vector3(data.attack_pos.x, 0, data.attack_pos.z);
jobHandle = Entities.ForEach((Entity entity, int entityInQueryIndex, in EnemyNavComponentData data, in Translation t, in DynamicBuffer<Child> children) =>
        {
            var distance = Vector3.Distance(t.Value, pos);
            if (distance > data.radius) return;
            ecb.RemoveComponent<EnemyNavComponentData>(entityInQueryIndex, entity);
            for (int i = 0; i < children.Length; i++)
            {
                ecb.DestroyEntity(entityInQueryIndex, children[i].Value);
            }
            ecb.DestroyEntity(entityInQueryIndex, entity);
        }).ScheduleParallel(jobHandle);
        jobHandle.Complete();

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions