Skip to content

Commit 09995e3

Browse files
andriyDevmockersf
authored andcommitted
Fix lightmaps freeing the wrong slab on removal. (#21564)
# Objective - Fixes #21551. - Fixes #20688. ## Solution - Insert slab_index instead of slot_index into free_slabs. ## Testing Ran the repro in #20688 and it works!
1 parent 6abcace commit 09995e3

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

  • crates/bevy_pbr/src/lightmap

crates/bevy_pbr/src/lightmap/mod.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ impl RenderLightmaps {
388388
slab.remove(fallback_images, slot_index);
389389

390390
if !slab.is_full() {
391-
self.free_slabs.grow_and_insert(slot_index.into());
391+
self.free_slabs.grow_and_insert(slab_index.into());
392392
}
393393
}
394394
}
@@ -417,6 +417,10 @@ impl LightmapSlab {
417417
}
418418

419419
fn allocate(&mut self, image_id: AssetId<Image>) -> LightmapSlotIndex {
420+
assert!(
421+
!self.is_full(),
422+
"Attempting to allocate on a full lightmap slab"
423+
);
420424
let index = LightmapSlotIndex::from(self.free_slots_bitmask.trailing_zeros());
421425
self.free_slots_bitmask &= !(1 << u32::from(index));
422426
self.lightmaps[usize::from(index)].asset_id = Some(image_id);

0 commit comments

Comments
 (0)