ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange |
1 | initial version |
Finally managed to solve the issue myself.
The issue was with the pointer usage of the Octree created inside the callback. It needed to be deleted but since i passed it to the "evaluatorObject" by pointer i was not sure where i had to delete it. (inside object or inside callback). Because of this, i decided to use smart pointers. "std::shared_ptr" to be exact.
i changed the callback from
void mapCallback(const octomap_msgs::Octomap::ConstPtr &msg)
{
octomap::AbstractOcTree* tree = octomap_msgs::msgToMap(*msg);
octomap::OcTree* tree_oct = dynamic_cast<octomap::OcTree*>(tree);
evaluatorObject.update_tree(tree_oct);
}
to
void mapCallback(const octomap_msgs::Octomap::ConstPtr &msg)
{
std::shared_ptr<octomap::OcTree> tree = std::shared_ptr<octomap::OcTree> (dynamic_cast<octomap::OcTree*> (octomap_msgs::msgToMap(*msg)));
evaluatorObject.update_tree(tree);
}
and it solved the issue.
2 | No.2 Revision |
Finally managed to solve the issue myself.
The issue was with the pointer usage of the Octree created inside the callback. It needed to be deleted but since i passed it to the "evaluatorObject" by pointer i was not sure where i had to delete it. (inside object or inside callback). Because of this, i decided to use smart pointers. "std::shared_ptr" to be exact.
i changed the callback from
void mapCallback(const octomap_msgs::Octomap::ConstPtr &msg)
{
octomap::AbstractOcTree* tree = octomap_msgs::msgToMap(*msg);
octomap::OcTree* tree_oct = dynamic_cast<octomap::OcTree*>(tree);
evaluatorObject.update_tree(tree_oct);
}
to
void mapCallback(const octomap_msgs::Octomap::ConstPtr &msg)
{
std::shared_ptr<octomap::OcTree> tree = std::shared_ptr<octomap::OcTree> (dynamic_cast<octomap::OcTree*> (octomap_msgs::msgToMap(*msg)));
evaluatorObject.update_tree(tree);
}
and it solved the issue.