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

Best time to delete entities? Getting rendering errors on removal

Discussion in 'Graphics for ECS' started by BigRookGames, Nov 10, 2020.

  1. BigRookGames

    BigRookGames

    Joined:
    Nov 24, 2014
    Posts:
    329
    I am wondering if it is best to destroy entities at a certain time in the cycle because I am receiving an error once in a while when an entity is destroyed:

    Code (CSharp):
    1. IndexOutOfRangeException: Index 6 is out of range of '6' Length.
    2. Unity.Collections.NativeArray`1[T].FailOutOfRangeError (System.Int32 index) (at <bb4ed9929fe04849bbe2b059cba4d31f>:0)
    3. Unity.Collections.NativeArray`1[T].CheckElementReadAccess (System.Int32 index) (at <bb4ed9929fe04849bbe2b059cba4d31f>:0)
    4. Unity.Collections.NativeArray`1[T].get_Item (System.Int32 index) (at <bb4ed9929fe04849bbe2b059cba4d31f>:0)
    5. 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)
    6. 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)
    7. 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)
    any idea what might help with this error? It happens on the frame that I destroy an entity.
     
  2. DreamingImLatios

    DreamingImLatios

    Joined:
    Jun 3, 2017
    Posts:
    3,983
    Unless you are doing some sort of structural change inside of PresentationSystemGroup between bounds updates and rendering, this looks like a Hybrid Renderer bug.
     
    BigRookGames likes this.
  3. nobeerleft

    nobeerleft

    Joined:
    Mar 29, 2012
    Posts:
    27

    Its a bug in HybridCullingV2, I mentioned a fix in the Hybrid Renderer thread.

    The graceDistance features allows batches to go out of date as they are not refreshed when an entity is deleted.

    I simply turned off the graceDistance feature of the LOD culling and all the glitchy issues with LODs (having to move camera to get updates) and that crash goes away.

    LIne 155 of HybridV2Culling.cs

    Code (CSharp):
    1.                         float graceDistance = 0.0f;
    This generally only causes a crash when you move the camera backwards, which never happened in Megacity, which is how this crash is still here.
    Code (CSharp):
    1. /*
    2. * This culling approach oriented from Megacity and works well for relatively
    3. * slow-moving cameras in a large, dense environment.
    4. *
    5. * The primary CPU costs involved in culling all the chunks of mesh instances
    6. * in megacity is touching the chunks of memory. A naive culling approach would
    7. * look like this:
    8. ...
    9.  
    10. * - Because the camera moves relatively slowly, we can compute a grace
    11. *   distance which the camera has to move (in any direction) before the LOD
    12. *   selection would compute a different result
    13. */
    If you delete an entity before the grace distance is up the culling crashes because the entity doesnt exist any more. If you are moving forward it never happens because the deleted entity chunk is culled in its entirety.
     
  4. BigRookGames

    BigRookGames

    Joined:
    Nov 24, 2014
    Posts:
    329
    Thank you so much for the post!