Skip to content

Commit

Permalink
Fix segmentation fault on out-of-map
Browse files Browse the repository at this point in the history
  • Loading branch information
at-wat committed Aug 23, 2023
1 parent 574f633 commit 559cff7
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions planner_cspace/src/distance_map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,12 @@ void DistanceMap::update(
const Astar::Vec e_rough(e[0], e[1], 0);
const Astar::Vec s_rough(s[0], s[1], 0);

if (s_rough.isExceeded(g_.size()) || e_rough.isExceeded(g_.size()))
{
// Out of the map
return;
}

if (cost_min != std::numeric_limits<float>::max())
{
pq_erase_.emplace(0.0, 0.0, p_cost_min);
Expand Down Expand Up @@ -342,13 +348,19 @@ void DistanceMap::update(

void DistanceMap::create(const Astar::Vec& s, const Astar::Vec& e)
{
const Astar::Vec e_rough(e[0], e[1], 0);
const Astar::Vec s_rough(s[0], s[1], 0);

if (s_rough.isExceeded(g_.size()) || e_rough.isExceeded(g_.size()))
{
// Out of the map
return;
}

pq_open_.clear();
pq_erase_.clear();
g_.clear(std::numeric_limits<float>::max());

const Astar::Vec e_rough(e[0], e[1], 0);
const Astar::Vec s_rough(s[0], s[1], 0);

g_[e_rough] = -p_.euclid_cost[0] * 0.5; // Decrement to reduce calculation error
pq_open_.push(Astar::PriorityVec(g_[e_rough], g_[e_rough], e_rough));
fillCostmap(pq_open_, s_rough);
Expand Down

0 comments on commit 559cff7

Please sign in to comment.