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:
Eero Lehtinen 2024-09-17 01:54:01 +03:00 committed by GitHub
parent 9bda913e36
commit db525e660e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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);
}
}