bevyengine/bevy · critical
Entity not in bin
Error message
Entity not in bin
What it means
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.
Source
Thrown at crates/bevy_render/src/render_phase/mod.rs:345
/// Because binned mesh instances are tightly packed in the buffers, we use
/// `swap_remove`, which swaps the last element to fill the place of the
/// entity that was removed. This might change the
/// [`RenderBinnedMeshInstanceIndex`] of some *other* entity, requiring the
/// caller to perform additional bookkeeping. This method returns the index
/// of the displaced entity, if there was one.
#[must_use]
fn remove(
&mut self,
bin: &mut RenderMultidrawableBin,
bin_index: RenderBinIndex,
entity_to_remove: MainEntity,
) -> RenderMultidrawableBatchSetGpuInstanceRemovalResult {
// Remove the entity from the `entity_to_binned_mesh_instance_index`
// map.
let removed_instance_index = bin
.entity_to_binned_mesh_instance_index
.remove(&entity_to_remove)
.expect("Entity not in bin");
let bin_metadata_index =
self.bin_index_to_bin_metadata_index_buffer.values()[bin_index.0 as usize];
self.bin_metadata_buffer.values_mut()[bin_metadata_index as usize].instance_count -= 1;
debug_assert_eq!(
self.bin_metadata_buffer.values()[bin_metadata_index as usize].instance_count as usize,
bin.entity_to_binned_mesh_instance_index.len()
);
// Remove the entity from the `render_binned_mesh_instance_buffer` list.
// Because binned mesh instance indices must be contiguous, this
// requires use of `swap_remove`.
self.render_binned_mesh_instance_buffer
.swap_remove(removed_instance_index.0 as usize);
// If an entity was displaced (i.e. has a new binned mesh instance index
// now), then return that to the caller so that they can perform
// whatever bookkeeping is necessary.View on GitHub (pinned to 221e52ae32)
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.
Defensive patterns
Strategy: fallback
Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.
Related errors
- Bin should be present
- Bin not present
- Bin key not present
- Cannot call `ReflectComponent::reflect_mut` on component {na
- Cannot call `ReflectComponent::reflect_unchecked_mut` on com
AI-assisted analysis of bevyengine/bevy@221e52ae32 (2026-08-20).
Data as JSON: /api/errors/e6c130f2fca52399.
Report an issue: GitHub.