Skip to content

Removing RigidBodyDisabled causes panic on next collision with a collider constructed with trimesh_from_mesh #1067

Description

@bytemunch

Wordy title! Unsure why, something to do with islands somehow.

The relevant logs:
thread 'main' (4138510) panicked at /home/sam/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/avian3d-0.7.0/src/
dynamics/solver/islands/mod.rs:518:9:
assertion failed: contact.island.is_none()
stack backtrace:
   0: __rustc::rust_begin_unwind
             at /rustc/8925ea358a0f265ca61026aadc7ecc506c545cbe/library/std/src/panicking.rs:679:5
   1: core::panicking::panic_fmt
             at /rustc/8925ea358a0f265ca61026aadc7ecc506c545cbe/library/core/src/panicking.rs:80:14
   2: core::panicking::panic
             at /rustc/8925ea358a0f265ca61026aadc7ecc506c545cbe/library/core/src/panicking.rs:150:5
   3: ::add_contact
             at /home/sam/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/avian3d-0.7.0/src/dynamics/solver/isla
nds/mod.rs:518:9
   4: >::u
pdate::<()>
             at /home/sam/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/avian3d-0.7.0/src/collision/narrow_pha
se/system_param.rs:343:46
   5: avian3d::collision::narrow_phase::update_narrow_phase::
             at /home/sam/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/avian3d-0.7.0/src/collision/narrow_pha
se/mod.rs:288:18
   6:  as co
re::ops::function::FnMut<(avian3d::collision::narrow_phase::system_param::NarrowPhase, bevy_ecs::message::message_writer::MessageWriter, bevy_ecs::message::message_writer::MessageWriter, bevy_ecs::c
hange_detection::params::Res, bevy_ecs::system::system_param::StaticSystemParam<()>, bevy_ecs:
:system::system_param::StaticSystemParam<()>, bevy_ecs::system::commands::parallel_scope::ParallelCommands, bevy_ecs:
:change_detection::params::ResMut)>>::call_mut
             at /home/sam/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/o
ps/function.rs:166:5
   7: <&mut avian3d::collision::narrow_phase::update_narrow_phase 
as core::ops::function::FnMut<(avian3d::collision::narrow_phase::system_param::NarrowPhase, bevy_ecs::message::message_writer::MessageWriter, bevy_ecs::message::message_writer::MessageWriter, bevy_e
cs::change_detection::params::Res, bevy_ecs::system::system_param::StaticSystemParam<()>, bevy
_ecs::system::system_param::StaticSystemParam<()>, bevy_ecs::system::commands::parallel_scope::ParallelCommands, bevy
_ecs::change_detection::params::ResMut)>>::call_mut
             at /home/sam/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/o
ps/function.rs:298:21
   8: <_ as bevy_ecs::system::function_system::SystemParamFunction _>>::run::call_inner
::<(), avian3d::collision::narrow_phase::system_param::NarrowPhase, be
vy_ecs::message::message_writer::MessageWriter, bevy_ecs::messa
ge::message_writer::MessageWriter, bevy_ecs::change_detection::pa
rams::Res, bevy_ecs::system::system_param::StaticSystemParam<()>, bevy_ecs::system::system_par
am::StaticSystemParam<()>, bevy_ecs::system::commands::parallel_scope::ParallelCommands, bevy_ecs::change_detection::
params::ResMut, &mut avian3d::collision::narrow_phase::update_
narrow_phase>
             at /home/sam/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/bevy_ecs-0.19.1/src/system/function_sy
stem.rs:904:21
   9:  as be
vy_ecs::system::function_system::SystemParamFunction, bevy_ecs::message::message_writer::MessageWriter, bevy_ecs::message::message_writer::MessageWriter, bevy_ecs::change_detection::params::Res, bevy_ecs::system::system_param::St
aticSystemParam<()>, bevy_ecs::system::system_param::StaticSystemParam<()>, bevy_ecs::system::commands::parallel_scop
e::ParallelCommands, bevy_ecs::change_detection::params::ResMut)>>::run
             at /home/sam/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/bevy_ecs-0.19.1/src/system/function_sy
stem.rs:907:17
  10: , bevy_ecs::message::message_writer::MessageWriter, bevy_ecs::message::message_writer::MessageWriter, bevy_ecs::change_detection::params::Res, bevy_ecs::system::system_param
::StaticSystemParam<()>, bevy_ecs::system::system_param::StaticSystemParam<()>, bevy_ecs::system::commands::parallel_
scope::ParallelCommands, bevy_ecs::change_detection::params::ResMut), (), (), avian3d::collision::narrow_phase::update_narrow_phase> as bevy_ecs::system::system::System>::run_unsafe
             at /home/sam/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/bevy_ecs-0.19.1/src/system/function_sy
stem.rs:696:29
  11: , bevy_ecs::message::message_writer::MessageWriter, bevy_ecs::message::message_writer::MessageWriter, bevy_ecs::change_detection::params::Res, bevy_ecs::system::system_param
::StaticSystemParam<()>, bevy_ecs::system::system_param::StaticSystemParam<()>, bevy_ecs::system::commands::parallel_
scope::ParallelCommands, bevy_ecs::change_detection::params::ResMut), (), (), avian3d::collision::narrow_phase::update_narrow_phase> as bevy_ecs::system::system::System>::run_without_applying_deferred
             at /home/sam/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/bevy_ecs-0.19.1/src/system/system.rs:147:23
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
Encountered a panic in system `avian3d::collision::narrow_phase::update_narrow_phase`!
Encountered a panic in system `avian3d::schedule::run_physics_schedule`!
Encountered a panic in system `bevy_app::main_schedule::FixedMain::run_fixed_main`!
Encountered a panic in system `bevy_time::fixed::run_fixed_main_schedule`!
Encountered a panic in system `bevy_app::main_schedule::Main::run_main`!
2026-09-16T21:39:20.766571Z  WARN bevy_ecs::world::command_queue: CommandQueue has un-applied commands being dropped. Did you forget to call SystemState::apply? caller:Location { file: "/home/sam/.cargo/registry/src/index.crates.io-1949c
f8c6b5b557f/avian3d-0.7.0/src/collider_tree/optimization.rs", line: 274, column: 33 }
2026-09-16T21:39:20.766617Z  WARN bevy_ecs::world::command_queue: CommandQueue has un-applied commands being dropped. Did you forget to call SystemState::apply? caller:Location { file: "/home/sam/.cargo/registry/src/index.crates.io-1949c
f8c6b5b557f/avian3d-0.7.0/src/collider_tree/optimization.rs", line: 274, column: 33 }
2026-09-16T21:39:20.766635Z  WARN bevy_ecs::world::command_queue: CommandQueue has un-applied commands being dropped. Did you forget to call SystemState::apply? caller:Location { file: "/home/sam/.cargo/registry/src/index.crates.io-1949c
f8c6b5b557f/avian3d-0.7.0/src/collider_tree/optimization.rs", line: 274, column: 33 }

Repro steps:

Create a scene with a RigidBodyDisabled collider and a trimesh_from_mesh collider.
Remove the RigidBodyDisabled component.
Collide the two colliders.

Reproduction Code:

use avian3d::prelude::*;
use bevy::prelude::*;

fn main() {
    App::new()
        .add_plugins((DefaultPlugins, PhysicsPlugins::default()))
        .add_systems(Startup, setup)
        .add_systems(Update, enable_rigid_bodies.run_if(run_once))
        .run();
}

fn setup(
    mut commands: Commands,
    mut materials: ResMut<Assets<StandardMaterial>>,
    mut meshes: ResMut<Assets<Mesh>>,
) {
    // Spawn disabled collider up in the sky
    commands.spawn((
        Transform::from_xyz(0.0, 10.0, 0.0),
        // Bug occurs on second touch, with no restitution or rotation panic does not occur
        Restitution::new(0.8),
        // Transform::from_xyz(0.0, 10.0, 0.0)
        //     .with_rotation(Quat::from_axis_angle(Vec3::Y, 1.0))
        //     .with_rotation(Quat::from_axis_angle(Vec3::Z, 1.0)),
        Mesh3d(meshes.add(Cuboid::new(1.0, 1.0, 1.0))),
        MeshMaterial3d(materials.add(Color::srgb(1.0, 0.0, 0.0))),
        Collider::cuboid(1.0, 1.0, 1.0),
        RigidBody::Dynamic,
        RigidBodyDisabled,
    ));

    // Spawn ground and generate a collider for the mesh using ColliderConstructor
    commands.spawn((
        Mesh3d(meshes.add(Plane3d::default().mesh().size(8.0, 8.0))),
        MeshMaterial3d(materials.add(Color::srgb(0.3, 0.5, 0.3))),
        ColliderConstructor::TrimeshFromMesh,
        RigidBody::Static,
    ));

    // Light
    commands.spawn((
        PointLight {
            intensity: 1_000_000.0,
            shadow_maps_enabled: true,
            ..default()
        },
        Transform::from_xyz(2.0, 8.0, 2.0),
    ));

    // Camera
    commands.spawn((
        Camera3d::default(),
        Transform::from_xyz(-5.0, 3.5, 5.5).looking_at(Vec3::ZERO, Vec3::Y),
    ));
}

// Re-enable the disabled collider
fn enable_rigid_bodies(mut commands: Commands, rbs: Query<Entity, With<RigidBodyDisabled>>) {
    for e in &rbs {
        commands.entity(e).remove::<RigidBodyDisabled>();
    }
}

Notably the reproduction above gives a slightly different error:

thread 'main' (4189685) panicked at crates/avian3d/../../src/dynamics/solver/islands/mod.rs:579:9:
assertion failed: self.contact_node(contact_id).is_none()
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Encountered a panic in system `avian3d::dynamics::solver::plugin::apply_contact_status_changes`!
Encountered a panic in system `avian3d::schedule::run_physics_schedule`!
Encountered a panic in system `bevy_app::main_schedule::FixedMain::run_fixed_main`!
Encountered a panic in system `bevy_time::fixed::run_fixed_main_schedule`!
Encountered a panic in system `bevy_app::main_schedule::Main::run_main`!

Upon further testing, I've found that the bug does not occur on the first collision, as shown by the now reduced example above. The panic only happens after the second touch.

Changing the collider to a convex_decomposition_from_mesh seems to avert this bug.

Even further testing seems to show that the bug is occurring when two or more contacts happen instantaneously. Playing with different collider constructor settings gives the cube slightly different bounces, and so sometimes the contacts are out of time with eachother, allowing the simulation to continue.

A better reproduction would test this directly but I'm a little out of my depth to write something targeted.

Even more digging throws up that this is probably something to do with the logic surrounding ContactPairFlags::STARTED_GENERATING_CONSTRAINTS. I'm still playing around with it but feels like I've narrowed down the possibilities for where this bug is hiding!

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-CollisionRelates to the broad phase, narrow phase, colliders, or other collision functionalityC-BugSomething isn't workingP-CrashA sudden unexpected crash

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions