Closed vilcans closed 3 years ago
Seems similar to #177, but that shows another panic.
I found a way to reliably reproduce the bug, so I've looked more into it. Some findings:
It doesn't matter if I change the collider in place using *collider.shape_mut().as_capsule_mut().unwrap() = capsule;
or collider.set_shape(SharedShape(Arc::new(capsule)));
. It still panics.
My code changes the position in addition to the collider. It doesn't make a difference if I set the position before or after modifying the collider. Or if I don't update the position at all. It still panics.
I found a workaround (that I thought I had already tried): Remove the collider and create a new one instead.
colliders.remove(old_collider_handle, bodies, false);
colliders.insert(create_collider(), body_handle, bodies);
Then there's no panic anymore.
Thank you for the details about this bug. I managed to reproduce the panic from #177 as well as the swap_remove
panic you reported in this issue. I did not reproduce the assertion failure you mentioned, but chances are that fixing that swap_remove
panic will also result in the assertion failure being fixed.
Feel free to reopen this issue if you are still having problems after #185 is merged.
I have observed these two panics in broad_phase_multi_sap. I suspect they are related, but I don't know how to reproduce the error.
I suspect they started appearing once I implemented a feature that updates the collider of an existing object, to make it grow or shrink while it moves. The code is similar to this:
FWIW, I can still reproduce it even if I recreate the PhysicsPipeline instance for every tick.
Panic traces
swap_remove
Error is always the same: len == 0, but tries to do swap_remove(0).
assertion failed
Here the numbers may vary.