mirror of
https://github.com/bevyengine/bevy
synced 2024-11-10 07:04:33 +00:00
Fix MeshAllocator
panic (#14560)
# Objective Fixes #14540 ## Solution - Clean slab layouts from stale `SlabId`s when freeing meshes - Technically performance requirements of freeing now increase based on the number of existing meshes, but maybe it doesn't matter too much in practice - This was the case before this PR too, but it's technically possible to free and allocate 2^32 times and overflow with `SlabId`s and cause incorrect behavior. It looks like new meshes would then override old ones. ## Testing - Tested in `loading_screen` example and tapping keyboard 1 and 2.
This commit is contained in:
parent
9bda913e36
commit
db525e660e
1 changed files with 6 additions and 0 deletions
|
@ -588,6 +588,12 @@ impl MeshAllocator {
|
|||
}
|
||||
|
||||
for empty_slab in empty_slabs {
|
||||
self.slab_layouts.values_mut().for_each(|slab_ids| {
|
||||
let idx = slab_ids.iter().position(|&slab_id| slab_id == empty_slab);
|
||||
if let Some(idx) = idx {
|
||||
slab_ids.remove(idx);
|
||||
}
|
||||
});
|
||||
self.slabs.remove(&empty_slab);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue