Skip to content

Commit e16a44c

Browse files
author
Leif Terry
committed
Use mutex to protect costmap reads.
Otherwise costmap can be read during a map update and return 0.
1 parent 57dd8d4 commit e16a44c

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

nav2_costmap_2d/src/costmap_2d.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,16 +265,19 @@ unsigned char * Costmap2D::getCharMap() const
265265

266266
unsigned char Costmap2D::getCost(unsigned int mx, unsigned int my) const
267267
{
268+
std::unique_lock<mutex_t> lock(*access_);
268269
return costmap_[getIndex(mx, my)];
269270
}
270271

271272
unsigned char Costmap2D::getCost(unsigned int undex) const
272273
{
274+
std::unique_lock<mutex_t> lock(*access_);
273275
return costmap_[undex];
274276
}
275277

276278
void Costmap2D::setCost(unsigned int mx, unsigned int my, unsigned char cost)
277279
{
280+
std::unique_lock<mutex_t> lock(*access_);
278281
costmap_[getIndex(mx, my)] = cost;
279282
}
280283

0 commit comments

Comments
 (0)