Ask Your Question
0

Segmentation fault (core dumped) : PCL tutorial

asked 2016-09-23 02:46:28 -0600

CocoJambo gravatar image

updated 2016-09-23 07:43:49 -0600

Hey, I am new to ROS (Version Jade-1.11.20) and want to work with pointclouds. I followed the first ROS PCL tutorial as written in http://wiki.ros.org/pcl/Tutorials . However, rosrun leads to the following error output:

rosrun my_pcl_tutorial example input:=/narrow_stereo_textured/points2
Segmentation fault (core dumped)

Normally, that would mean that pointers are screwed up, but as I simply copy-pasted the code from the tutorial, the following example.cpp file should be correct:

#include <ros/ros.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/filters/voxel_grid.h>

ros::Publisher pub;

void 
cloud_cb (const sensor_msgs::PointCloud2ConstPtr& cloud_msg)
{
  // Container for original & filtered data
  pcl::PCLPointCloud2* cloud = new pcl::PCLPointCloud2; 
  pcl::PCLPointCloud2ConstPtr cloudPtr(cloud);
  pcl::PCLPointCloud2 cloud_filtered;

  // Convert to PCL data type
  pcl_conversions::toPCL(*cloud_msg, *cloud);

  // Perform the actual filtering
  pcl::VoxelGrid<pcl::PCLPointCloud2> sor;
  sor.setInputCloud (cloudPtr);
  sor.setLeafSize (0.1, 0.1, 0.1);
  sor.filter (cloud_filtered);

  // Convert to ROS data type
  sensor_msgs::PointCloud2 output;
  pcl_conversions::fromPCL(cloud_filtered, output);

  // Publish the data
  pub.publish (output);
}

int
main (int argc, char** argv)
{
  // Initialize ROS
  ros::init (argc, argv, "my_pcl_tutorial");
  ros::NodeHandle nh;

  // Create a ROS subscriber for the input point cloud
  ros::Subscriber sub = nh.subscribe ("input", 1, cloud_cb);

  // Create a ROS publisher for the output point cloud
  pub = nh.advertise<sensor_msgs::PointCloud2> ("output", 1);

  // Spin
  ros::spin ();
}

Could it be that I need to manually download and put /narrow_stereo_textured/points2 in the same folder as example.cpp ? I assumed that it gets taken from the library, but maybe this assumption is wrong. If you need any further code or info, just tell me (you would have to give all instructions though). I also had a problem incorporating the package before as can be read in http://answers.ros.org/question/24426... .

GDB bt output:

        (gdb) bt
    #0  0x00007ffff402ea70 in boost::math::lanczos::lanczos_initializer<boost::math::lanczos::lanczos17m64, long double>::init::init() ()
       from /usr/lib/libpcl_sample_consensus.so.1.7
    #1  0x00007ffff40066be in ?? () from /usr/lib/libpcl_sample_consensus.so.1.7
    #2  0x00007ffff7dea10a in call_init (l=<optimized out>, argc=argc@entry=1, 
        argv=argv@entry=0x7fffffffd9c8, env=env@entry=0x7fffffffd9d8)
        at dl-init.c:78
    #3  0x00007ffff7dea1f3 in call_init (env=<optimized out>, 
        argv=<optimized out>, argc=<optimized out>, l=<optimized out>)
        at dl-init.c:36
    #4  _dl_init (main_map=0x7ffff7ffe1c8, argc=1, argv=0x7fffffffd9c8, 
        env=0x7fffffffd9d8) at dl-init.c:126
    #5  0x00007ffff7ddb30a in _dl_start_user () from /lib64/ld-linux-x86-64.so.2
    #6  0x0000000000000001 in ?? ()
    #7  0x00007fffffffddd1 in ?? ()
    #8  0x0000000000000000 in ?? ()
(gdb)
edit retag flag offensive close merge delete

Comments

1

Probably easiest to run your node in GDB and debug it. You can do this either directly (starting the node binary from lib in your devel space), or by using a launch prefix: wiki/roslaunch/nodes in gdb.

gvdhoorn gravatar imagegvdhoorn ( 2016-09-23 03:15:45 -0600 )edit

Well, this is difficult for me to grasp. I built a launch file in my_pcl_tutorial/launch and tried to run it with the prefixes, but it did not work. Could you give step by step instructions for simply doing what I am supposed to do?

CocoJambo gravatar imageCocoJambo ( 2016-09-23 04:14:44 -0600 )edit

The first would be to actually tell us what "did not work".

gvdhoorn gravatar imagegvdhoorn ( 2016-09-23 04:49:13 -0600 )edit

I never used GDB :>. Would gdb example invoked in the lib/my_pcl_tutorial workspace be sufficient? The output is attached to the question. Additionally, I have not written launch files until yet and find it hard to transfer the launch files written in tutorials to my specific example.

CocoJambo gravatar imageCocoJambo ( 2016-09-23 06:18:50 -0600 )edit

The launch file (probably something wrong there):

<launch>
  <group ns="example1">
    <node pkg="my_pcl_tutorial" name="sim" type="example"/>
  </group>
</launch>

I am listening to gdb tutorials on youtube now. I am wondering if it is easier to debug with qtcreator.

CocoJambo gravatar imageCocoJambo ( 2016-09-23 06:19:18 -0600 )edit
1

gdb example would work, yes. Start the rest of your application (ie: other nodes, and a roscore). After that, return to gdb, enter r (short for run) and press enter. That should start your node. Wait for the crash, enter bt (backtrace), enter. Copy/paste the backtrace in your question.

gvdhoorn gravatar imagegvdhoorn ( 2016-09-23 07:26:00 -0600 )edit

Make sure to compile your node with debug symbols though.

gvdhoorn gravatar imagegvdhoorn ( 2016-09-23 07:31:23 -0600 )edit
2

And this may all seem overly complicated to solve your problem, but if you're going to be working in C/C++, knowing how to use gdb for tracking down a simple SEGFAULT is a really valuable skill.

re: qt creator: also possible. But that is basically gdb with a UI.

gvdhoorn gravatar imagegvdhoorn ( 2016-09-23 07:32:58 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2016-09-26 04:27:26 -0600

gvdhoorn gravatar image

(based on information provided in the comments)

This looks like the PCL1.7<->C++11 incompatibility.

I'd try to find out whether you are enabling/forcing C++11 compilation somehow, but a work-around would be to compile with Debug symbols enabled.

Either run catkin_make with -DCMAKE_BUILD_TYPE=Debug or -DCMAKE_BUILD_TYPE=RelWithDebInfo.

edit flag offensive delete link more

Comments

For me it didn't work with -DCMAKE_BUILD_TYPE=Debug. Instead it worked when compiling in Release mode.However, the solution to this which I found is https://github.com/felixendres/rgbdsl...

ksb gravatar imageksb ( 2019-08-13 17:15:15 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2016-09-23 02:46:28 -0600

Seen: 2,334 times

Last updated: Sep 26 '16