bevy_rapier icon indicating copy to clipboard operation
bevy_rapier copied to clipboard

Panic in narrow_phase after "pause" using rapier_config.physics_pipeline_active = false

Open Elogain opened this issue 3 years ago • 2 comments

Hello!

Im getting a panic after resuming the RapierConfiguration physics_pipeline_active after having it set to false for a while. Basically, I pause the simulation as the player is presented with a level-up window. Once it is closed I resume the physics simulation (among other things). Every now and then (1 out of 100?) I get bitten by a panic on this line:

https://github.com/dimforge/bevy_rapier/blob/master/src/plugin/narrow_phase.rs#L307

My code causing the call to collider2() is basically:

for contact_pair in rapier_context.contacts_with(player_entity) {
        let other_collider = if contact_pair.collider1() == player_entity {
            contact_pair.collider2()
        } else {
            contact_pair.collider1()
        };
        ...
}

The code lives in a system that runs every frame.

It feels like it might be some weird condition in the frame where bevy state is changed from ingame -> levelup and the removal of an entity that would have been collider2() in that same frame. Perhaps it mucks up the state in contacts vs what the bevy-rapier "sync removals" method removes. It seems like just as it unpauses and the system that panics runs it'll look at stale collider data that still has a collision with an entity that was removed in that frame where the gamestate changed (simulation paused). Am using version 0.13.1.

Elogain avatar May 29 '22 00:05 Elogain

Also getting this crash seemingly at random in 0.18.0. My code doesn't set physics_pipeline_active to false at any point, however. Sorry I can't be of any more help.

BenGale93 avatar Nov 13 '22 14:11 BenGale93

I have a bit more info to go on. My bevy app is a simulation, so I often leave it for some time. This crash often happens when I go back to my PC and wake the monitors up from standby. I have absolutely no idea why this might be the cause but it might help someone else.

BenGale93 avatar Nov 20 '22 20:11 BenGale93