I am trying to process a Point Cloud read from a depth camera using the pcl library. Sometimes, while the node that does the filtering is running, the node crash and this is the last output on the screen before the crash:

[camera_to_occupancy-2] [INFO] [1709140099.438141571] [occupancy_map_manager]: Pointcloud size: 47500
[camera_to_occupancy-2] [INFO] [1709140099.579901997] [occupancy_map_manager]: Pointcloud size: 50482
[camera_to_occupancy-2] [INFO] [1709140099.875375689] [occupancy_map_manager]: Pointcloud size: 58103
[camera_to_occupancy-2] [pcl::KdTreeFLANN::setInputCloud] Cannot create a KDTree with an empty input cloud!
[camera_to_occupancy-2] [pcl::KdTreeFLANN::setInputCloud] Cannot create a KDTree with an empty input cloud!

So I think the crash might be connected to an "empty pointcloud" as the KDTreeFLANN is signaling. Nonetheless, when trying to print the dimension of the cloud, it never seems to be empty, and I also return from the callback if there are less than 100 points in the pointcloud.

The slice of the code where I think the bug is located is the following:

 // Extract Objects
  RCLCPP_INFO(this->get_logger(), "Pointcloud size: %ld", current_pointcloud->size());
  pcl::search::KdTree<pcl::PointXYZ>::Ptr tree(new pcl::search::KdTree<pcl::PointXYZ>);
  std::vector<pcl::PointIndices> cluster_indices;
  pcl::EuclideanClusterExtraction<pcl::PointXYZ> euclidean_clusters;

1 Answer 1


try skipping the filtering process if the current point cloud size is zero. That might help. Right now you're passing point cloud regardless of whether it's empty or not. You can use an if condition before attempting filtering.

  • $\begingroup$ Maybe it was not very clear from my description of the problem, but the function I wrote returns before the filtering if there are less than 100 points in the PointCloud. So I find it weird that it complains about an empty PointCloud being passed. $\endgroup$ Commented Feb 29 at 9:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.