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

Question Dynamic Buffer issue

Discussion in 'Entity Component System' started by Chris-Herold, Jun 6, 2023.

  1. Chris-Herold

    Chris-Herold

    Joined:
    Nov 14, 2011
    Posts:
    115
    Entities 1.0

    Job 1 (System A):
    1. Create Entity with parallelwriter ECB
    2. AddBuffer<T> (off-chunk)
    3. AppendToBuffer<T>
    4. ECB executes at end of SystemGroup A

    Job 2 (System B):
    1. backwards for loop DynamicBuffer<T>
    2. check element, if criteria met RemoveAt(i)
    3. if buffer empty, remove buffer via parallel ECB
    4. ECB executes at end of SystemGroup B

    Result:

    Index 0 is out of range, but buffer is Length > 0

    I've been banging my head against this for days and i'm failing to see what i'm doing wrong.
    My code worked without issues in 0.51 - upgrading to 1.0 seemingly broke DynamicBuffers or ECBs or both.

    Anyone else experiencing this?
     
    Last edited: Jun 6, 2023
  2. Chris-Herold

    Chris-Herold

    Joined:
    Nov 14, 2011
    Posts:
    115
    Second issue:

    Using ComponentLookup with a corrupt Entity Index - produced by a corrupt IBufferElementData with one Entity field (result of issue #1) - crashes the Editor. Error log shows either Entity is still deferred or Entity Index is larger than EntityStore Capacity.

    Losing my sanity.
     
    Last edited: Jun 6, 2023
  3. xVergilx

    xVergilx

    Joined:
    Dec 22, 2014
    Posts:
    3,292
    Try submitting minimal bug repro. If it happens outside your project in a clean environment - then its most likely a bug.

    As an alternative solution - try writing to the buffer directly via BufferLookup instead of ECB.
    Not everything has to be parallel or deferred in order to be fast. Maybe there's a better solution but its hard to find out one without an actual context.