ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange |
1 | initial version |
This really isn't a PCL thing, it's C++ and pointers. The issue with your original code is these lines:
const PointCloud *points_in;
if (blah) {
PointCloud transformed_points;
points_in = &transformed_points;
}
transformed_points is a local variable, so it is created on the stack. When you hit the end of the if() block, it goes out of scope - your pointer is now pointing at an invalid address. When you access it, you'll corrupt your stack!
In your newer code, you create a shared_ptr and assign it storage with the "new" command:
const PointCloud::Ptr points_in (new PointCloud);
This is on the heap, not the stack, and so it continues to be valid later on.