Skip to content

QBVH rebalance still panics at 'attempt to add with overflow' #146

@Jondolf

Description

@Jondolf

Bevy XPBD is using Parry internally for spatial queries, and the rebalance method of Qbvh is causing panics with the error 'attempt to add with overflow'. #139 claims to fix this, but it doesn't seem like it, although the error is on a slightly different line.

thread 'TaskPool (6)' panicked at 'attempt to add with overflow', /home/nisevoid/.cargo/registry/src/index.crates.io-6f17d22bba15001f/parry3d-0.13.5/src/partitioning/qbvh/update.rs:367:54
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Encountered a panic in system `bevy_xpbd_3d::plugins::spatial_query::update_query_pipeline`!
Encountered a panic in exclusive system `bevy_xpbd_3d::plugins::setup::run_physics_schedule`!
Encountered a panic in system `bevy_app::main_schedule::Main::run_main`!

This is the code that calls rebalance, in the update_incremental method, similar to Rapier's query pipeline:

if refit_and_balance {
    let _ = self.qbvh.refit(0.0, &mut self.workspace, |entity_index| {
        // Construct entity ID (used as key in a hash map)
        let generation = self.entity_generations.get(entity_index).map_or(0, |i| *i);
        let entity = Entity::from_bits((generation as u64) << 32 | *entity_index as u64);
        // Compute and return AABB
        let (iso, shape) = colliders.get(&entity).unwrap();
        shape.compute_aabb(iso)
    });
    self.qbvh.rebalance(0.0, &mut self.workspace);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions