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

Segmentation fault when creating a large number of entities #272

Open
PaulGao96 opened this issue Oct 13, 2023 · 1 comment
Open

Segmentation fault when creating a large number of entities #272

PaulGao96 opened this issue Oct 13, 2023 · 1 comment

Comments

@PaulGao96
Copy link

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?

@PaulGao96
Copy link
Author

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?

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