I am currently working with ROS 2 humble on Ubuntu Ubuntu 22.04.3 and a rosbag pointcloud. However, now I am getting a [ros2run] Segmentation fault when I start my node. I do only get the error, when I am trying to visualize the pointcloud with PCL 1.12.1. If I comment out the viewer, the fault is not occuring. Do you have any ideas what might cause this problem and how I can fix it?
#include <rclcpp/rclcpp.hpp>
#include <sensor_msgs/msg/point_cloud2.hpp>
#include <pcl_conversions/pcl_conversions.h>
#include <pcl/point_cloud.h>
#include <pcl/visualization/cloud_viewer.h>
class SimplePointCloudSubscriber : public rclcpp::Node
{
public:
SimplePointCloudSubscriber() : Node("simple_point_cloud_subscriber")
{
subscription_ = this->create_subscription<sensor_msgs::msg::PointCloud2>(
"/velodyne_points", 10,
std::bind(&SimplePointCloudSubscriber::pointCloudCallback, this, std::placeholders::_1));
}
private:
void pointCloudCallback(const sensor_msgs::msg::PointCloud2::SharedPtr msg)
{
RCLCPP_INFO(this->get_logger(), "Received PointCloud2 message");
pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZ>());
pcl::fromROSMsg(*msg, *cloud);
viewer_.showCloud(cloud);
}
rclcpp::Subscription<sensor_msgs::msg::PointCloud2>::SharedPtr subscription_;
pcl::visualization::CloudViewer viewer_{"Simple Cloud Viewer"};
};
int main(int argc, char **argv)
{
rclcpp::init(argc, argv);
rclcpp::spin(std::make_shared<SimplePointCloudSubscriber>());
rclcpp::shutdown();
return 0;
}
The problem you are experiencing is likely this one: https://github.com/PointCloudLibrary/pcl/issues/5237 Tldr: there was a bug in VTK (dependency of PCL), easiest fix is using a newer version of PCL (at least PCL 1.13.0).