diff --git a/nav2_smac_planner/src/a_star.cpp b/nav2_smac_planner/src/a_star.cpp index deaa597b923..b6a56271a93 100644 --- a/nav2_smac_planner/src/a_star.cpp +++ b/nav2_smac_planner/src/a_star.cpp @@ -117,8 +117,11 @@ template typename AStarAlgorithm::NodePtr AStarAlgorithm::addToGraph( const unsigned int & index) { - // Emplace will only create a new object if it doesn't already exist. - // If an element exists, it will return the existing object, not create a new one. + auto iter = _graph.find(index); + if (iter != _graph.end()) { + return &(iter->second); + } + return &(_graph.emplace(index, NodeT(index)).first->second); }