Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SimpleCullingJob Throw IndexOutOfRangeException When Destroying Lod Entities from ecb #10

Open
DANaini13 opened this issue Mar 17, 2022 · 0 comments

Comments

@DANaini13
Copy link

DANaini13 commented Mar 17, 2022

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/[email protected]/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/[email protected]/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/[email protected]/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();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant