diff --git a/grid_map_core/src/GridMap.cpp b/grid_map_core/src/GridMap.cpp index b8633a661..b5924e751 100644 --- a/grid_map_core/src/GridMap.cpp +++ b/grid_map_core/src/GridMap.cpp @@ -782,6 +782,9 @@ bool GridMap::atPositionLinearInterpolated(const std::string& layer, const Posit getIndex(position, indices[0]); getPosition(indices[0], point); + if (!checkIfIndexInRange(indices[0], size_)) { + return false; + } if (position.x() >= point.x()) { indices[1] = indices[0] + Index(-1, 0); // Second point is above first point. @@ -790,6 +793,9 @@ bool GridMap::atPositionLinearInterpolated(const std::string& layer, const Posit indices[1] = indices[0] + Index(+1, 0); idxTempDir = false; } + if (!checkIfIndexInRange(indices[1], size_)) { + return false; + } if (position.y() >= point.y()) { indices[2] = indices[0] + Index(0, -1); // Third point is right of first point. if (idxTempDir) { @@ -818,6 +824,10 @@ bool GridMap::atPositionLinearInterpolated(const std::string& layer, const Posit idxShift[3] = 0; } } + if (!checkIfIndexInRange(indices[2], size_)) { + return false; + } + indices[3].x() = indices[1].x(); indices[3].y() = indices[2].y();