diff --git a/octree/include/pcl/octree/impl/octree_pointcloud_adjacency.hpp b/octree/include/pcl/octree/impl/octree_pointcloud_adjacency.hpp index 8d84f627b00..f9ba3d39c68 100644 --- a/octree/include/pcl/octree/impl/octree_pointcloud_adjacency.hpp +++ b/octree/include/pcl/octree/impl/octree_pointcloud_adjacency.hpp @@ -184,13 +184,22 @@ pcl::octree::OctreePointCloudAdjacency for (int dx = -1; dx <= 1; ++dx) { + int x = dx + key_arg.x; + if (x < 0 || x > this->max_key_.x) + continue; + neighbor_key.x = static_cast (x); for (int dy = -1; dy <= 1; ++dy) { + int y = dy + key_arg.y; + if (y < 0 || y > this->max_key_.y) + continue; + neighbor_key.y = static_cast (y); for (int dz = -1; dz <= 1; ++dz) { - neighbor_key.x = key_arg.x + dx; - neighbor_key.y = key_arg.y + dy; - neighbor_key.z = key_arg.z + dz; + int z = dz + key_arg.z; + if (z < 0 || z > this->max_key_.z) + continue; + neighbor_key.z = static_cast (z); LeafContainerT *neighbor = this->findLeaf (neighbor_key); if (neighbor) {