{"record":{"id":"d50e313e417584d2","repo":"bevyengine/bevy","slug":"too-many-entities","errorCode":null,"errorMessage":"too many entities","messagePattern":"too many entities","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/bevy_ecs/src/entity/remote_allocator.rs","lineNumber":770,"sourceCode":"}\n\nimpl FreshAllocator {\n    /// This exists because it may possibly change depending on platform.\n    /// Ex: We may want this to be smaller on 32 bit platforms at some point.\n    const MAX_ENTITIES: u32 = u32::MAX;\n\n    /// The total number of indices given out.\n    #[inline]\n    fn total_entity_indices(&self) -> u32 {\n        self.next_entity_index.load(Ordering::Relaxed)\n    }\n\n    /// This just panics.\n    /// It is included to help with branch prediction, and put the panic message in one spot.\n    #[cold]\n    #[inline]\n    fn on_overflow() -> ! {\n        panic!(\"too many entities\")\n    }\n\n    /// Allocates a fresh [`EntityIndex`].\n    /// This row has never been given out before.\n    #[inline]\n    fn alloc(&self) -> Entity {\n        let index = self.next_entity_index.fetch_add(1, Ordering::Relaxed);\n        if index == Self::MAX_ENTITIES {\n            Self::on_overflow();\n        }\n        // SAFETY: We just checked that this was not max and we only added 1, so we can't have missed it.\n        Entity::from_index(unsafe { EntityIndex::new(NonMaxU32::new_unchecked(index)) })\n    }\n\n    /// Allocates `count` [`EntityIndex`]s.\n    /// These rows will be fresh.\n    /// They have never been given out before.\n    fn alloc_many(&self, count: u32) -> AllocUniqueEntityIndexIterator {","sourceCodeStart":752,"sourceCodeEnd":788,"githubUrl":"https://github.com/bevyengine/bevy/blob/396ca727080776bd313bb892423b7d94e03b81b4/crates/bevy_ecs/src/entity/remote_allocator.rs#L752-L788","documentation":"Cold-path panic in FreshAllocator::on_overflow: the atomic next_entity_index reached MAX_ENTITIES (u32::MAX), so the allocator can never hand out another fresh index. This is an aggregate capacity exhaustion across all frees/allocations in this allocator, not a per-frame spike; the helper exists to keep the panic message and branch in one place.","triggerScenarios":"Thrown at crates/bevy_ecs/src/entity/remote_allocator.rs:770 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Free and recycle entity indices (despawn) instead of allocating indefinitely","Reduce entity churn: reuse pools for frequently spawned/despawned entities","For truly enormous workloads, shard work across multiple Worlds/allocators"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"396ca727080776bd313bb892423b7d94e03b81b4","analyzedAt":"2026-08-20T16:12:39.808Z","contentChangedAt":"2026-08-20T16:12:39.808Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}