0

I wrote a simple test program that creates 100 entities per frame, each entity has a buffer, as follows:

void Execute(Entity projectileEntity, [ChunkIndexInQuery] int chunkIndex, ref LocalTransform transform, in Projectile projectile)
{
    for(int j = 0; j < 100; j++) {
        var e = ECBWriter.CreateEntity(chunkIndex);
        var as_path = ECBWriter.AddBuffer<ASN>(chunkIndex, e);
        for(uint i = 0; i < 10; i++){
            as_path.Add(new ASN { routerID = i });
        }
    }
}

I compiled the program to run on a linux server, after running for some time, it crashed after about 2e8 entities had been created, there are ~1e6 chunks and took up 22GB of RAM, but my linux server had 128GB of RAM. The error is as follows:

(Editor: 2022.3.5f1c1 with Entities-1.0.14)

Caught fatal signal - signo:11 code:1 errno:0 addr:(nil)
Segmentation fault (core dumped)

(Editor: 2021.3.11f1c2 with Entities-0.51.1-preview.21)


Caught fatal signal - signo:11 code:1 errno:0 addr:(nil)
Obtained 6 stack frames.
#0  0x007f6752ad9980 in funlockfile
#1  0x007f6705882ac4 in Unity.Entities.ChunkDataUtility.AddEmptyChunk(Unity.Entities.Archetype* archetype, Unity.Entities.Chunk* chunk, Unity.Entities.SharedComponentValues sharedComponentValues) -> void_08f2b62234a514a789dc69881ac7811a
#2  0x007f6705890f29 in Unity.Entities.EntityComponentStore.GetChunkWithEmptySlotsWithAddedComponent(Unity.Entities.EntityComponentStore* this, Unity.Entities.Chunk* srcChunk, Unity.Entities.ComponentType componentType, int sharedComponentIndex) -> Unity.Entities.Chunk*_08f2b62234a514a789dc69881ac7811a
#3  0x007f67058dfaf0 in Unity.Entities.EntityDataAccess.AddComponentDuringStructuralChange(Unity.Entities.EntityDataAccess* this, Unity.Entities.Entity entity, Unity.Entities.ComponentType componentType, ref Unity.Entities.SystemHandleUntyped originSystem) -> bool_08f2b62234a514a789dc69881ac7811a
#4  0x007f67058ddd14 in Unity.Entities.EntityCommandBuffer.EcbWalker`1<Unity.Entities.EntityCommandBuffer.PlaybackProcessor>.ProcessChain(Unity.Entities.EntityCommandBuffer.EcbWalker`1<Unity.Entities.EntityCommandBuffer.PlaybackProcessor>* this, Unity.Entities.ECBChainPlaybackState* chainStates, int currentChain, int nextChain) -> void_08f2b62234a514a789dc69881ac7811a
#5  0x000000404b8e18 in (wrapper managed-to-native) object:wrapper_native_0x7f6705982900 (intptr,int,intptr,int,int)
Segmentation fault (core dumped)

Why is there an error at AddEmptyChunk before the memory ran out?

3
  • I found the reason. Looking through the entities source code, I found this: ` internal const long k_MaximumEntitiesPerWorld = 128L * 1024L * 1024L; // roughly 128 million Entities per World, maximum ` The number of entities I created exceeded the limit. Can k_MaximumEntitiesPerWorld be set larger? Commented Oct 14, 2023 at 11:02
  • Why would you need > 128 million entities ? Commented Oct 18, 2023 at 9:16
  • Essentially, I wanted to implement a 2-D array (buffer within buffer) data structure and I found that ECS does not support this directly. I had to do this: each element of the outer buffer contains an entity (reference), and then AddBuffer on that entity. Then I had a two-dimensional buffer. However, that would require me to create a lot of entities. Given the scale of the game I'm building, the number of entities will exceed this limit. Commented Oct 20, 2023 at 6:53

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.