Fix off-by-one in alloc_many unintentionally allocating fresh indices#22785
Conversation
The condition 'current_len < self.free.len()' should be '<=' to handle the case where current_len equals free.len() (i.e., when the free list has exactly the number of entities we need to allocate). Without this fix, spawn_batch would allocate fresh indices instead of reusing freed ones when current_len == free.len().
|
Your PR caused a change in the graphical output of an example or rendering test. This might be intentional, but it could also mean that something broke! If it's expected, please add the M-Deliberate-Rendering-Change label. If this change seems unrelated to your PR, you can consider updating your PR to target the latest main branch, either by rebasing or merging main into it. |
|
Given that this is fixed on main but we can't cleanly cherrpick an existing fix I think this is the least bad way to do this. |
ElliottjPierce
left a comment
There was a problem hiding this comment.
Yup! My bad.
Funnily enough, I actually made nearly the exact same mistake in the new allocator and had to fix it there too. Shows the importance of good unit tests I guess.
Thanks for finding and fixing this!
|
@alice-i-cecile shouldn't the test have been added to main as well, or is it no longer relevant there? I tried it on main and it compiles fine, but it fails when run. |
We have other tests on main that cover this now. The bug was in the new allocator, but I fixed that and added additional tests. The tests I added sort and dedupe instead of computing the intersection, but same thing really. The reason this test fails on main is because we have a This |
Objective
Currently there is an off-by-one bug in
alloc_many.spawn_batchwould allocate fresh indices instead of reusing freed ones when current_len == free.len().I don't believe this bug exists on
main, hence why this PR is targeting 0.18.1. Please let me know if there is a better way to land this change.Testing