Segmentation fault in PCL segmentation project
I am working on a segmentation project with PCL, but i am receiving a Segmentation fault (core dumped)
error. Unfortunately i dont get much more error than that, but i have determined that the segmentation function is causing the problem. I hope someone can spot my typo/mistake, as i am becoming more and more blind in the code.
void cloud_cb (const sensor_msgs::PointCloud2& pc2_raw)
{
pcl::PointCloud<pcl::PointXYZ>::Ptr pcl_cloud(new pcl::PointCloud<pcl::PointXYZ>);
pcl::PointCloud<pcl::PointXYZ>::Ptr temp_cloud(new pcl::PointCloud<pcl::PointXYZ>);
// Convert PC2 to PCL
pcl::fromROSMsg(pc2_raw,*pcl_cloud);
// Create variables for segmentation
pcl::ModelCoefficients::Ptr coefficient (new pcl::ModelCoefficients);
pcl::PointIndices::Ptr inliers (new pcl::PointIndices);
pcl::search::KdTree<pcl::PointXYZ>::Ptr search(new pcl::search::KdTree<pcl::PointXYZ>);
pcl::SACSegmentation<pcl::PointXYZ> segmentation;
// Set segmentation variables
segmentation.setOptimizeCoefficients(true);
segmentation.setModelType(pcl::SACMODEL_PLANE);
segmentation.setMethodType(pcl::SAC_RANSAC);
segmentation.setDistanceThreshold(0.5);
segmentation.setSamplesMaxDist(1.0, search);
segmentation.setMaxIterations(1000);
// Start segmentation
pcl::copyPointCloud(*pcl_cloud,*temp_cloud);
search->setInputCloud(temp_cloud);
segmentation.segment(*inliers, *coefficient);
}
gdb backtrace:
#0 0xb785cecd in pcl::SACSegmentation<pcl::PointXYZ>::segment(pcl::PointIndices&, pcl::ModelCoefficients&) () from /usr/lib/libpcl_segmentation.so.1.7
#1 0x08074bfc in cloud_cb (pc2_raw=...) at /home/mirex/catkin_ws/src/isa_cuda/src/cuda.cpp:48
#2 0x080816e0 in boost::detail::function::void_function_invoker1<void (*)(sensor_msgs::PointCloud2_<std::allocator<void> > const&), void, sensor_msgs::PointCloud2_<std::allocator<void> > const&>::invoke (
function_ptr=..., a0=...) at /usr/include/boost/function/function_template.hpp:112
#3 0x080872ab in boost::function1<void, sensor_msgs::PointCloud2_<std::allocator<void> > const&>::operator() (this=0x80c47c4, a0=...) at /usr/include/boost/function/function_template.hpp:1013
#4 0x08086b95 in ros::SubscriptionCallbackHelperT<sensor_msgs::PointCloud2_<std::allocator<void> > const&, void>::call (this=0x80c47c0, params=...)
at /opt/ros/hydro/include/ros/subscription_callback_helper.h:180
#5 0xb7f89497 in ros::SubscriptionQueue::call() () from /opt/ros/hydro/lib/libroscpp.so
#6 0xb7f38117 in ros::CallbackQueue::callOneCB(ros::CallbackQueue::TLS*) () from /opt/ros/hydro/lib/libroscpp.so
#7 0xb7f39c24 in ros::CallbackQueue::callAvailable(ros::WallDuration) () from /opt/ros/hydro/lib/libroscpp.so
#8 0xb7f8cad8 in ros::SingleThreadedSpinner::spin(ros::CallbackQueue*) () from /opt/ros/hydro/lib/libroscpp.so
#9 0xb7f70b87 in ros::spin(ros::Spinner&) () from /opt/ros/hydro/lib/libroscpp.so
#10 0xb7f70bb8 in ros::spin() () from /opt/ros/hydro/lib/libroscpp.so
#11 0x08074f15 in main (argc=1, argv=0xbffff054) at /home/mirex/catkin_ws/src/isa_cuda/src/cuda.cpp:77