#Setting shared component every frame seems to break EntityComponentStore

1 messages · Page 1 of 1 (latest)

winter sleet
#
Expected: True
EntityCommandBuffer was recorded in DefaultNamespace.LinkedTest and played back in Unity.Entities.EndSimulationEntityCommandBufferSystem.
  at UnityEngine.Assertions.Assert.Fail (System.String message, System.String userMessage) [0x00043] in <1d5ae28f5ca3488dbddca7794af65eb1>:0 
  at UnityEngine.Assertions.Assert.IsTrue (System.Boolean condition, System.String message) [0x0000f] in <1d5ae28f5ca3488dbddca7794af65eb1>:0 
  at UnityEngine.Assertions.Assert.IsTrue (System.Boolean condition) [0x00009] in <1d5ae28f5ca3488dbddca7794af65eb1>:0 
  at Unity.Assertions.Assert.IsTrue (System.Boolean condition) [0x00008] in .\Library\PackageCache\com.unity.entities@1.0.0-pre.65\Unity.Entities\Stubs\Unity.Assertions\Assert.cs:24 
  at Unity.Entities.EntityComponentStore.RemoveSharedComponentReference_Unmanaged (System.Int32 sharedComponentIndex, System.Int32 numRefs) [0x00046] in .\Library\PackageCache\com.unity.entities@1.0.0-pre.65\Unity.Entities\EntityComponentStore.cs:1697 
  at Unity.Entities.ChunkDataUtility.ReleaseChunk (Unity.Entities.Chunk* chunk) [0x00049] in .\Library\PackageCache\com.unity.entities@1.0.0-pre.65\Unity.Entities\ChunkDataUtility.cs:823 
  at Unity.Entities.ChunkDataUtility.SetChunkCountKeepMetaChunk (Unity.Entities.Chunk* chunk, System.Int32 newCount) [0x00017] in .\Library\PackageCache\com.unity.entities@1.0.0-pre.65\Unity.Entities\ChunkDataUtility.cs:847 
  at Unity.Entities.ChunkDataUtility.SetChunkCount (Unity.Entities.Chunk* chunk, System.Int32 newCount) [0x00033] in .\Library\PackageCache\com.unity.entities@1.0.0-pre.65\Unity.Entities\ChunkDataUtility.cs:879```
#

Setting a shared component every frame seems to just break things really bad

        [BurstCompile]
        [WithAll(typeof(TestShared))]
        private partial struct MixJob : IJobEntity
        {
            public EntityCommandBuffer EntityCommandBuffer;

            public int Offset;

            private void Execute(Entity entity)
            {
                var random = Random.CreateFromIndex((uint)math.clamp(entity.Index ^ this.Offset, 0, uint.MaxValue - 1));
                this.EntityCommandBuffer.SetSharedComponent(entity, new TestShared { Value = (byte)random.NextInt(0, 4) });
            }
        }```
#

just starts failing after ~3 seconds

#

This is obviously not something you'd be doing in an actual game I was just writing a stress test for something
Assuming I'm not missing something obvious I've done wrong, seems to imply an underlying issue somewhere

#
new MixJob
    {
        EntityCommandBuffer = SystemAPI.GetSingleton<EndSimulationEntityCommandBufferSystem.Singleton>().CreateCommandBuffer(state.WorldUnmanaged),
        Offset = ++this.offset,
    }
    .Schedule();```
#

entity count == 2

#
private struct TestShared : ISharedComponentData
{
    public byte Value;
}```
torn cedar
#

on first glance entityComponentStore->RemoveSharedComponentReference_Unmanaged(sharedComponentIndex); numRefs isn't provided internal void RemoveSharedComponentReference_Unmanaged(int sharedComponentIndex, int numRefs = 1)

surreal sail
#

Thanks for the report; I'll take a look at this when I'm back in the office next week

winter sleet
#

I'm intending to get up a small repo / bug ticket when I find a moment

#

If I do I'll post it here

winter sleet
#

Well my first attempt at a smaller repo failed, and adding the above code back to my original slightly larger now nets a new error after ~3 seconds =S

#
EntityCommandBuffer was recorded in BovineLabs.LinkedTest and played back in Unity.Entities.EndSimulationEntityCommandBufferSystem.
  at Unity.Entities.EntityComponentStore.InsertSharedComponent_Unmanaged (Unity.Entities.TypeIndex typeIndex, System.Int32 hashCode, System.Void* data, System.Void* defaultValue) [0x0011e] in .\Library\PackageCache\com.unity.entities@1.0.0-pre.65\Unity.Entities\EntityComponentStore.cs:1597 
  at Unity.Entities.EntityDataAccess.SetSharedComponentDataAddrDefaultMustBeNullDuringStructuralChange (Unity.Collections.NativeArray`1[T] entities, Unity.Entities.TypeIndex typeIndex, System.Int32 hashCode, System.Void* componentDataAddr, Unity.Entities.SystemHandle& originSystem) [0x0004e] in .\Library\PackageCache\com.unity.entities@1.0.0-pre.65\Unity.Entities\EntityDataAccess.cs:1980 
  at Unity.Entities.EntityCommandBuffer+PlaybackProcessor.SetUnmanagedSharedComponentData (Unity.Entities.BasicCommand* header) [0x0002e] in .\Library\PackageCache\com.unity.entities@1.0.0-pre.65\Unity.Entities\EntityCommandBuffer.cs:4332```
#

OK I seem to have a fix

#

I didn't implement IEquatable on my shared component

#

I swear not implementing IEquatable on a shared component used to be an error if you hadn't implemented this back in 0.51?

#

Doing this fixes issues

#

and just to confirm, commenting out IEquatable interface causes error to happen again

#

So I'm not sure if this is an error with implementation @surreal sail or there is simply a check missing somewhere to inform users to implement IEquatable<T> for ISharedComponentData

#

If IEquatable<T> is not meant to be required, I can upload this full repo (it's not large), let me know

gray bear
#

it’s definitely not required for unmanaged shared components

#

I may have just fixed this bug, although in the repro I had (which came from the forums) the error message was different

#

The repro was also setting shared components every frame, and it did indeed blow up after a few seconds

#

We should note somewhere that for unmanaged shared components it’s actually faster to not implement iequatable

#

If you do manage to find a repro I’d love to try it on master to see if it’s fixed

#

Said fix will also be in the next version, which is coming along reasonably soon now

winter sleet
#

i have a very solid repo here toggle component on/off breaks it

#

but it keeps erroring in different ways

#

now it's appearing as the original assert failed into

Unity.Entities.EntityComponentStore.RemoveSharedComponentReference_Unmanaged (System.Int32 sharedComponentIndex, System.Int32 numRefs) (at ./Library/PackageCache/com.unity.entities@1.0.0-pre.65/Unity.Entities/EntityComponentStore.cs:1737)
Unity.Entities.ChunkDataUtility.ReleaseChunk (Unity.Entities.Chunk* chunk) (at ./Library/PackageCache/com.unity.entities@1.0.0-pre.65/Unity.Entities/ChunkDataUtility.cs:823)```
#

i'll zip this up for you if you want

gray bear
#

That error is the one I fixed but yeah I’d take a zip for sure

winter sleet
#

ok got it as a small repo without my library attached