spinonce crashed in callback function of subscriber

asked 2015-11-03 16:55:23 -0500

Sameow gravatar image

updated 2015-11-05 18:31:08 -0500

Hello, All,

I am trying to visualize point cloud in real time. And I have transferred data from pointcloud2 to pointcloud<t>. Then I used PCLVisualization to visualize the point cloud. The viewer is in the callback function. It worked fine at the beginning and then the callback function just crashed with segmentation fault. To check which part is wrong of callback function, I used a very stupid method that put a ROS_INFO after each sentence, and found it crashed in spinonce(). But I could not figure out what is wrong here with spinonce. Could you help me debug this?

#include <ros/ros.h>
// #include <timer.h>
// PCL specific includes
#include <sensor_msgs/PointCloud2.h>
#include <pcl_conversions/pcl_conversions.h>
#include <pcl/point_cloud.h>
#include <pcl/point_types.h>
#include <pcl/io/io.h>
#include <pcl/io/pcd_io.h>
#include <pcl_ros/point_cloud.h>

#include <boost/thread/thread.hpp>
#include <pcl/common/common_headers.h>
#include <pcl/features/normal_3d.h>
#include <pcl/visualization/pcl_visualizer.h>
#include <pcl/console/parse.h>
#include <pcl/visualization/cloud_viewer.h>
#include <pcl/visualization/point_cloud_color_handlers.h>

typedef pcl::PointCloud<pcl::PointXYZI> PCLCloud;
boost::shared_ptr<pcl::visualization::PCLVisualizer> viewer (new pcl::visualization::PCLVisualizer ("3D Viewer"));

cloud_cb (const PCLCloud::ConstPtr& input)
    // ros::Time begin = ros::Time::now();
    // boost::shared_ptr<pcl::visualization::PCLVisualizer> viewer (new pcl::visualization::PCLVisualizer ("3D Viewer"));
    viewer->setBackgroundColor(0, 0, 0);
pcl::visualization::PointCloudColorHandlerGenericField<pcl::PointXYZI> intensity_distribution(input, "intensity");
// if(!viewer->updatePointCloud<pcl::PointXYZI> (input, intensity_distribution, "pc_data"))
    viewer->addPointCloud<pcl::PointXYZI> (input, intensity_distribution, "pc_data");
    viewer->spinOnce ();
    // boost::this_thread::sleep (boost::posix_time::microseconds (100000));
    // viewer->spinOnce();
    // ros::Time final = ros::Time::now();
    // ros::Time dura=final - begin;
    // ROS_INFO("%f",dura);

main (int argc, char** argv)  
  // Initialize ROS
  ros::init (argc, argv, "point_cloud");
  ros::NodeHandle nh; 
  // Create a ROS subscriber for the input point cloud
  ros::Subscriber sub = nh.subscribe ("output", 1, cloud_cb);

ros::Rate rate(10.0);
  while (nh.ok())
  // Spin
  // ros::spin ();

The output topic releases the point cloud data every 100ms. I just worry that maybe during the process of callback function, the new data is subscribed to the node and it cannot continue processing.

It is my assumption and I am really not sure. I really need your help.

Thank you for your help.

I got the trace of GDB. I hope it will help to debug.

Program received signal SIGSEGV, Segmentation fault.
0x00007fffd9605ad7 in ?? () from /usr/lib/x86_64-linux-gnu/dri/swrast_dri.so
(gdb) backtrace
#0  0x00007fffd9605ad7 in ?? ()
   from /usr/lib/x86_64-linux-gnu/dri/swrast_dri.so
#1  0x00007ffff6e4919a in vtkOpenGLPainterDeviceAdapter::SendAttribute(int, int, int, void const*, long long) () from /usr/lib/libvtkRendering.so.5.8
#2  0x00007ffff6d70768 in vtkPointsPainter::RenderPrimitive(unsigned long, vtkDataArray*, vtkUnsignedCharArray*, vtkDataArray*, vtkRenderer*) ()
   from /usr/lib/libvtkRendering.so.5.8
#3  0x00007ffff6d7d6db in vtkPrimitivePainter::RenderInternal(vtkRenderer*, vtkActor*, unsigned long, bool) () from /usr/lib/libvtkRendering.so.5.8
#4  0x00007ffff6d75fca in vtkPolyDataPainter::Render(vtkRenderer*, vtkActor*, unsigned long, bool) () from /usr/lib/libvtkRendering.so.5.8
#5  0x00007ffff6c8a5c1 in vtkChooserPainter::RenderInternal(vtkRenderer*, vtkActor ...
edit retag flag offensive close merge delete