{"record":{"id":"37951fbd5de38514","repo":"bevyengine/bevy","slug":"bin-key-not-present","errorCode":null,"errorMessage":"Bin key not present","messagePattern":"Bin key not present","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"crates/bevy_render/src/render_phase/mod.rs","lineNumber":609,"sourceCode":"                .insert(bin, main_entity, input_uniform_index, bin_index);\n\n        self.instance_count += 1;\n        debug_assert_eq!(\n            binned_mesh_instance_index.0 as usize,\n            self.binned_mesh_instance_index_to_entity.len()\n        );\n        self.binned_mesh_instance_index_to_entity.push(main_entity);\n    }\n\n    /// Removes the given entity from the bin with the given key.\n    ///\n    /// The given entity must be present in that bin.\n    fn remove(&mut self, main_entity: MainEntity, bin_key: &BPI::BinKey) {\n        // Fetch the bin index.\n        let bin_index = *self\n            .bin_key_to_bin_index\n            .get(bin_key)\n            .expect(\"Bin key not present\");\n        let bin = self.bins[bin_index.0 as usize].as_mut().unwrap();\n\n        let instance_removal_result = self.gpu_buffers.remove(bin, bin_index, main_entity);\n\n        // Because the instance is removed with `swap_remove`, we have two cases\n        // to consider.\n        match instance_removal_result.displaced_instance {\n            // Case 1: The instance was removed from the middle of the array. In\n            // that case, we have a *displaced entity* that was swapped in to\n            // fill the hole. We need to update the table that maps binned mesh\n            // instance index to entity and the reverse table that maps entity\n            // to binned mesh instance index.\n            Some((displaced_instance_index, displaced_instance)) => {\n                debug_assert_eq!(\n                    displaced_instance_index.0 + 1,\n                    self.binned_mesh_instance_index_to_entity.len() as u32\n                );\n                let displaced_entity = self.binned_mesh_instance_index_to_entity.pop().expect(","sourceCodeStart":591,"sourceCodeEnd":627,"githubUrl":"https://github.com/bevyengine/bevy/blob/221e52ae323febfd399bd7d067918fc43648cfb3/crates/bevy_render/src/render_phase/mod.rs#L591-L627","documentation":"remove() on the multidrawable bins (mod.rs:610) expects the bin_key to exist in bin_key_to_bin_index; the panic fires when an entity is removed under a key whose bin was already freed or never created. The documented contract is 'The given entity must be present in that bin', so the caller's key must match the one used at insertion.","triggerScenarios":"Removing an entity whose bin key (binning parameters derived from mesh/material state) no longer maps to an existing bin - the key changed between insertion and removal, or the bin was emptied/freed while the entity was still slated for removal, or the entity was already removed.","commonSituations":"Mutating mesh or material properties that feed the bin key in the same frame the entity is removed; double-removal through multiple code paths; engine bugs in the multidraw path across Bevy versions.","solutions":["Avoid changing bin-key-relevant mesh/material properties concurrently with entity removal in the same frame.","Ensure entities are removed from the phase once, through one path.","Upgrade Bevy to pick up bin lifecycle fixes.","Report upstream with a backtrace if no custom removal code is involved."],"exampleFix":null,"handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":["Do not change bin-key-relevant mesh/material properties in the same frame you remove the entity.","Remove entities from phases exactly once, through one code path.","Stay current on patch releases for multidraw lifecycle fixes."],"tags":["bevy","multidraw","bin-key","panic","removal"],"backgroundTag":"missing-map-key","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"}