{"record":{"id":"e6c130f2fca52399","repo":"bevyengine/bevy","slug":"entity-not-in-bin","errorCode":null,"errorMessage":"Entity not in bin","messagePattern":"Entity not in bin","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"crates/bevy_render/src/render_phase/mod.rs","lineNumber":345,"sourceCode":"    /// Because binned mesh instances are tightly packed in the buffers, we use\n    /// `swap_remove`, which swaps the last element to fill the place of the\n    /// entity that was removed. This might change the\n    /// [`RenderBinnedMeshInstanceIndex`] of some *other* entity, requiring the\n    /// caller to perform additional bookkeeping. This method returns the index\n    /// of the displaced entity, if there was one.\n    #[must_use]\n    fn remove(\n        &mut self,\n        bin: &mut RenderMultidrawableBin,\n        bin_index: RenderBinIndex,\n        entity_to_remove: MainEntity,\n    ) -> RenderMultidrawableBatchSetGpuInstanceRemovalResult {\n        // Remove the entity from the `entity_to_binned_mesh_instance_index`\n        // map.\n        let removed_instance_index = bin\n            .entity_to_binned_mesh_instance_index\n            .remove(&entity_to_remove)\n            .expect(\"Entity not in bin\");\n\n        let bin_metadata_index =\n            self.bin_index_to_bin_metadata_index_buffer.values()[bin_index.0 as usize];\n        self.bin_metadata_buffer.values_mut()[bin_metadata_index as usize].instance_count -= 1;\n        debug_assert_eq!(\n            self.bin_metadata_buffer.values()[bin_metadata_index as usize].instance_count as usize,\n            bin.entity_to_binned_mesh_instance_index.len()\n        );\n\n        // Remove the entity from the `render_binned_mesh_instance_buffer` list.\n        // Because binned mesh instance indices must be contiguous, this\n        // requires use of `swap_remove`.\n        self.render_binned_mesh_instance_buffer\n            .swap_remove(removed_instance_index.0 as usize);\n\n        // If an entity was displaced (i.e. has a new binned mesh instance index\n        // now), then return that to the caller so that they can perform\n        // whatever bookkeeping is necessary.","sourceCodeStart":327,"sourceCodeEnd":363,"githubUrl":"https://github.com/bevyengine/bevy/blob/221e52ae323febfd399bd7d067918fc43648cfb3/crates/bevy_render/src/render_phase/mod.rs#L327-L363","documentation":"An expect() inside RenderMultidrawableBinGpuBuffers::remove (mod.rs:346) that fires when the entity being removed is not present in the bin's entity_to_binned_mesh_instance_index map. The GPU-driven multidraw removal path requires that the entity was previously inserted into that exact bin; hitting this means removal was requested for an entity the bin does not track.","triggerScenarios":"An entity is removed from a multidrawable bin it was never added to or was already removed from: double removal of the same mesh instance in one frame, or bin bookkeeping updated twice for the same entity.","commonSituations":"Entities despawned while also having Mesh3d removed via separate code paths in the same frame; custom code calling the render-phase removal API manually; churn-heavy scenes on Bevy versions with the newer multidraw batching; engine regression after upgrading.","solutions":["Remove each entity from the render phase exactly once - despawn the entity OR remove the mesh component, not paths that trigger both.","Upgrade to the latest Bevy patch release (multidraw bin lifecycle fixes land regularly).","Audit any custom code that manipulates render phase bins or calls removal APIs directly.","If it reproduces without custom bin manipulation, minimize the repro and file a Bevy issue with the backtrace."],"exampleFix":null,"handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":["Trigger mesh removal through one path only (despawn OR remove the component), never both in a frame.","Keep Bevy patched up to date; multidraw bin fixes land in patch releases.","Avoid manipulating render phase bins from game code.","Keep a minimal repro handy and report engine-invariant panics upstream."],"tags":["bevy","multidraw","bin","panic","mesh-instance"],"backgroundTag":"internal-invariant-violation","analyzedSha":"221e52ae323febfd399bd7d067918fc43648cfb3","analyzedAt":"2026-08-20T16:12:39.808Z","contentChangedAt":"2026-08-20T16:12:39.808Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}