jeudi 26 avril 2018

Shared pointer segmentation faults -- how to properly share a PlanningScene?

ps_ptr is a boost shared pointer to a PlanningScene instance, created w/ boost::make_shared. The PlanningScene class is declared as,

class PlanningScene : private boost::noncopyable, public std::enable_shared_from_this<PlanningScene>

and includes a method clone for "copying" a planning scene.

These definitions imply to me there is a specific way this class is intended to be shared. What is the proper way to pass around ps_ptr? I would like to share it with another class SceneStuff, where SceneStuff only uses it to call a const method (PlanningScene::checkCollision).

Some notes:

  • Using ps_ptr as-is results in seg-faults due to double free or corruption. That's the compiler telling me I'm trying to free memory that has already been freed or was dereferenced, but shouldn't a boost::shared_ptr handle this? I've been through many SO threads on this topic, but to no avail.
  • I'm unable to call auto new_ps_ptr = ps_ptr->clone(ps_ptr); because no matching function for call to ‘planning_scene::PlanningScene::clone(boost::shared_ptr<planning_scene::PlanningScene>&)’
  • boost smart pointers docs

UPDATE: Thanks to Igor's comment I've switched ps_ptr to a std::shared_ptr, but still get seg-faults occasionally due to the following code (additionally invoked by SceneStuff)C:

// Setup collision-models
auto robot_model_ptr = ps_ptr->getRobotModel();
collision_detection::CollisionRobotFCL crobot(robot_model_ptr);
auto world_ptr = ps_ptr->getWorldNonConst();
collision_detection::CollisionWorldFCL cworld(world_ptr);

// Just standard structs
auto dreq = collision_detection::DistanceRequest();
auto dres = collision_detection::DistanceResult();

// Compute obstacle distances for the given `conf`
moveit::core::RobotState query_state = ps_ptr->getCurrentState();
query_state.setVariablePositions(x.data());  // x is simply an Eigen::VectorXd
cworld.distanceRobot(dreq, dres, crobot, query_state);

Here's the relevant source:

Aucun commentaire:

Enregistrer un commentaire