bulletphysics / bullet3

Bullet Physics SDK: real-time collision detection and multi-physics simulation for VR, games, visual effects, robotics, machine learning etc.

Home Page:http://bulletphysics.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Ubuntu 20: performDiscreteCollisionDetection() --> "pure virtual function called"

AndyZe opened this issue · comments

commented

I'm having a "Pure virtual function" issue with a basic collision detection app in Linux (ubuntu 20.04).

I can set up the btDiscreteDynamicsWorld just fine and the project compiles. I can print the object locations. But at runtime, this line:

collision_dynamics_world_->performDiscreteCollisionDetection();

gives "pure virtual method called. terminate called without an active exception".

Here are the relevant bits from my CMakeLists. Basically I tried anything possible to link against all Bullet libraries:

find_package(Bullet 2.87)

...

include_directories(
  SYSTEM
    ${BULLET_INCLUDE_DIRS}
)

...

add_executable(my_executable
  ...
)
target_link_libraries(
  my_executable
  # ${BULLET_LIBRARIES} doesn't include the Bullet3 libs for some reason...
  ${BULLET_LIBRARIES}
  # TODO: try removing these individually before merging.
  Bullet3Dynamics
  Bullet3Collision
  Bullet3Common
  Bullet3Geometry
  ${catkin_LIBRARIES}
)

I printed ${BULLET_LIBRARIES and ${BULLET_INCLUDE_DIRS} and these are the results:

BULLET_INCLUDE_DIRS="/usr/include/bullet"
BULLET_LIBRARIES="/usr/lib/x86_64-linux-gnu/libBulletDynamics.so/usr/lib/x86_64-linux-gnu/libBulletCollision.so/usr/lib/x86_64-linux-gnu/libLinearMath.so/usr/lib/x86_64-linux-gnu/libBulletSoftBody.so"

commented

I worked around this by using the lower-level API of std::unique_ptr<btCollisionDispatcher> dispatcher_. That's good enough for my purposes. I don't even use btCollisionWorld or btDiscreteDynamicWorld. I used the MoveIt implementation as an example:

https://github.com/ros-planning/moveit/blob/1a95deb9ccf8c1f8da65f6afcdc25878c5800f8f/moveit_core/collision_detection_bullet/src/bullet_integration/bullet_discrete_bvh_manager.cpp#L60

commented

I've found this issue can be caused by passing a pointer to a local variable, like this. This is bad:

  {
    btTransform tf;
    tf.setIdentity();
    tf.setOrigin(btVector3(1e5, 1e5, 1e5));
    bed_collision_object_->setWorldTransform(tf);
    btSphereShape sphere_shape(btScalar(0.1));  // Goes out of scope
    bed_collision_object_->setCollisionShape(&sphere_shape);
    addCollisionObjectToBroadphase(sphere_collision_object_, broadphase_, dispatcher_);
  }

Fixed version:

  btSphereShape sphere_shape(btScalar(0.1));
  {
    btTransform tf;
    tf.setIdentity();
    tf.setOrigin(btVector3(1e5, 1e5, 1e5));
    bed_collision_object_->setWorldTransform(tf);
    bed_collision_object_->setCollisionShape(&sphere_shape);
    addCollisionObjectToBroadphase(sphere_collision_object_, broadphase_, dispatcher_);
  }

So this was probably user error. Closing.