Robotics StackExchange | Archived questions

spinonce crashed in callback function of subscriber

Hello, All,

I am trying to visualize point cloud in real time. And I have transferred data from pointcloud2 to pointcloud. 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"));


void 
cloud_cb (const PCLCloud::ConstPtr& input)
{
    // ros::Time begin = ros::Time::now();
    viewer->removePointCloud("m8_data");
    // boost::shared_ptr<pcl::visualization::PCLVisualizer> viewer (new pcl::visualization::PCLVisualizer ("3D Viewer"));
    viewer->setBackgroundColor(0, 0, 0);
    viewer->addCoordinateSystem(1.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_INFO("[%d]",5);
    // ros::Time final = ros::Time::now();
    // ros::Time dura=final - begin;
    // ROS_INFO("%f",dura);
}


int
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())
  {
    ros::spinOnce();
    rate.sleep();
  }
  // 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*, unsigned long, bool) () from /usr/lib/libvtkRendering.so.5.8
#6  0x00007ffff6d75fca in vtkPolyDataPainter::Render(vtkRenderer*, vtkActor*, unsigned long, bool) () from /usr/lib/libvtkRendering.so.5.8
#7  0x00007ffff6d75fca in vtkPolyDataPainter::Render(vtkRenderer*, vtkActor*, unsigned long, bool) () from /usr/lib/libvtkRendering.so.5.8
#8  0x00007ffff6e63480 in vtkOpenGLRepresentationPainter::RenderInternal(vtkRenderer*, vtkActor*, unsigned long, bool) () from /usr/lib/libvtkRendering.so.5.8
#9  0x00007ffff6d75fca in vtkPolyDataPainter::Render(vtkRenderer*, vtkActor*, unsigned long, bool) () from /usr/lib/libvtkRendering.so.5.8
#10 0x00007ffff6e480de in vtkOpenGLLightingPainter::RenderInternal(vtkRenderer*, vtkActor*, unsigned long, bool) () from /usr/lib/libvtkRendering.so.5.8
---Type <return> to continue, or q <return> to quit---frame 2
#11 0x00007ffff6d75fca in vtkPolyDataPainter::Render(vtkRenderer*, vtkActor*, unsigned long, bool) () from /usr/lib/libvtkRendering.so.5.8
#12 0x00007ffff6e372ce in vtkOpenGLDisplayListPainter::RenderInternal(vtkRenderer*, vtkActor*, unsigned long, bool) () from /usr/lib/libvtkRendering.so.5.8
#13 0x00007ffff6e36803 in vtkOpenGLClipPlanesPainter::RenderInternal(vtkRenderer*, vtkActor*, unsigned long, bool) () from /usr/lib/libvtkRendering.so.5.8
#14 0x00007ffff6e63ac5 in vtkOpenGLScalarsToColorsPainter::RenderInternal(vtkRenderer*, vtkActor*, unsigned long, bool) () from /usr/lib/libvtkRendering.so.5.8
#15 0x00007ffff6d4646a in vtkPainterPolyDataMapper::RenderPiece(vtkRenderer*, vtkActor*) () from /usr/lib/libvtkRendering.so.5.8
#16 0x00007ffff6d7530e in vtkPolyDataMapper::Render(vtkRenderer*, vtkActor*) ()
   from /usr/lib/libvtkRendering.so.5.8
#17 0x00007ffff6c9187c in vtkDataSetMapper::Render(vtkRenderer*, vtkActor*) ()
   from /usr/lib/libvtkRendering.so.5.8
#18 0x00007ffff6e359c2 in vtkOpenGLActor::Render(vtkRenderer*, vtkMapper*) ()
   from /usr/lib/libvtkRendering.so.5.8
#19 0x00007ffff6d36259 in vtkLODActor::Render(vtkRenderer*, vtkMapper*) ()
   from /usr/lib/libvtkRendering.so.5.8
#20 0x00007ffff6d35b0f in vtkLODActor::RenderOpaqueGeometry(vtkViewport*) ()
   from /usr/lib/libvtkRendering.so.5.8
#21 0x00007ffff6d93407 in vtkRenderer::UpdateGeometry() ()
   from /usr/lib/libvtkRendering.so.5.8
#22 0x00007ffff6e5efc2 in vtkOpenGLRenderer::DeviceRender() ()
---Type <return> to continue, or q <return> to quit---return
   from /usr/lib/libvtkRendering.so.5.8
#23 0x00007ffff6d951dc in vtkRenderer::Render() ()
   from /usr/lib/libvtkRendering.so.5.8
#24 0x00007ffff6d9177a in vtkRendererCollection::Render() ()
   from /usr/lib/libvtkRendering.so.5.8
#25 0x00007ffff78519ee in pcl::visualization::PCLVisualizerInteractorStyle::OnTimer() () from /usr/lib/libpcl_visualization.so.1.7
#26 0x00007ffff6cd1678 in vtkInteractorStyle::ProcessEvents(vtkObject*, unsigned long, void*, void*) () from /usr/lib/libvtkRendering.so.5.8
#27 0x00007ffff7328009 in vtkCallbackCommand::Execute(vtkObject*, unsigned long, void*) () from /usr/lib/libvtkCommon.so.5.8
#28 0x00007ffff73f51b0 in ?? () from /usr/lib/libvtkCommon.so.5.8
#29 0x00007ffff6e1f732 in vtkXRenderWindowInteractorTimer(void*, unsigned long*) () from /usr/lib/libvtkRendering.so.5.8
#30 0x00007ffff0387a26 in ?? () from /usr/lib/x86_64-linux-gnu/libXt.so.6
#31 0x00007ffff038858f in XtAppNextEvent ()
   from /usr/lib/x86_64-linux-gnu/libXt.so.6
#32 0x00007ffff6e1e40c in vtkXRenderWindowInteractor::Start() ()
   from /usr/lib/libvtkRendering.so.5.8
#33 0x00007ffff7879b12 in pcl::visualization::PCLVisualizer::spinOnce(int, bool) () from /usr/lib/libpcl_visualization.so.1.7
#34 0x0000000000435c23 in cloud_cb(boost::shared_ptr<pcl::PointCloud<pcl::PointXYZI> const> const&) ()
---Type <return> to continue, or q <return> to quit---
#35 0x0000000000440d59 in boost::detail::function::void_function_invoker1<void (*)(boost::shared_ptr<pcl::PointCloud<pcl::PointXYZI> const> const&), void, boost::shared_ptr<pcl::PointCloud<pcl::PointXYZI> const> const&>::invoke(boost::detail::function::function_buffer&, boost::shared_ptr<pcl::PointCloud<pcl::PointXYZI> const> const&) ()
#36 0x00000000004437d7 in boost::function1<void, boost::shared_ptr<pcl::PointCloud<pcl::PointXYZI> const> const&>::operator()(boost::shared_ptr<pcl::PointCloud<pcl::PointXYZI> const> const&) const ()
#37 0x0000000000442405 in boost::detail::function::void_function_obj_invoker1<boost::function<void (boost::shared_ptr<pcl::PointCloud<pcl::PointXYZI> const> const&)>, void, boost::shared_ptr<pcl::PointCloud<pcl::PointXYZI> const> >::invoke(boost::detail::function::function_buffer&, boost::shared_ptr<pcl::PointCloud<pcl::PointXYZI> const>) ()
#38 0x00000000004469ae in boost::function1<void, boost::shared_ptr<pcl::PointCloud<pcl::PointXYZI> const> >::operator()(boost::shared_ptr<pcl::PointCloud<pcl::PointXYZI> const>) const ()
#39 0x0000000000445ba0 in ros::SubscriptionCallbackHelperT<boost::shared_ptr<pcl::PointCloud<pcl::PointXYZI> const> const&, void>::call(ros::SubscriptionCallbackHelperCallParams&) ()
#40 0x00007ffff69099b5 in ros::SubscriptionQueue::call() ()
   from /opt/ros/jade/lib/libroscpp.so
#41 0x00007ffff68c7767 in ros::CallbackQueue::callOneCB(ros::CallbackQueue::TLS*) () from /opt/ros/jade/lib/libroscpp.so
---Type <return> to continue, or q <return> to quit---
#42 0x00007ffff68c8573 in ros::CallbackQueue::callAvailable(ros::WallDuration)
    () from /opt/ros/jade/lib/libroscpp.so
#43 0x00007ffff68f4b05 in ros::spinOnce() ()
   from /opt/ros/jade/lib/libroscpp.so
#44 0x0000000000435f9d in main ()

I am not CS and very new to ROS and PCL. I would appreciate it if you could help me to sovle it. Thank you.

Asked by Sameow on 2015-11-03 17:55:23 UTC

Comments

Answers