I'm trying to match successive point clouds using the NDT. The NDT is used in the callback function of a ROS service. Every time the callback function executes, I instantiate a NormalDistributionsTransform<pcl::PointXYZ, pcl::PointXYZ>, set the source and target point clouds and execute the align method. This seems to work the first four or five times but then suddenly I get a segfault and the node crashes.
NDT shouldn't segfault, especially because it seems to work for a while before the issue occurs.
Repeated calls to NDT cause segfault somewhere deep inside the call stack.
See code below, it's rather straightforward, just repeatedly call NDT.
==173658== Invalid write of size 4
==173658== at 0x491C969: pcl::KdTreeFLANN<pcl::PointXYZ, flann::L2_Simple<float> >::radiusSearch(pcl::PointXYZ const&, double, std::vector<int, std::allocator<int> >&, std::vector<float, std::allocator<float> >&, unsigned int) const (in /home/riy2rng/.conda/envs/mamba/envs/myenv/lib/libpcl_kdtree.so.1.12.0)
==173658== by 0x2EF420: pcl::VoxelGridCovariance<pcl::PointXYZ>::radiusSearch(pcl::PointXYZ const&, double, std::vector<pcl::VoxelGridCovariance<pcl::PointXYZ>::Leaf const*, std::allocator<pcl::VoxelGridCovariance<pcl::PointXYZ>::Leaf const*> >&, std::vector<float, std::allocator<float> >&, unsigned int) const (in /home/riy2rng/Documents/ros/myslam_catkin_ws/devel/lib/myslam/ScanMatcher)
==173658== by 0x2EB074: pcl::NormalDistributionsTransform<pcl::PointXYZ, pcl::PointXYZ>::computeDerivatives(Eigen::Matrix<double, 6, 1, 0, 6, 1>&, Eigen::Matrix<double, 6, 6, 0, 6, 6>&, pcl::PointCloud<pcl::PointXYZ> const&, Eigen::Matrix<double, 6, 1, 0, 6, 1> const&, bool) (in /home/riy2rng/Documents/ros/myslam_catkin_ws/devel/lib/myslam/ScanMatcher)
==173658== by 0x2E8B42: pcl::NormalDistributionsTransform<pcl::PointXYZ, pcl::PointXYZ>::computeTransformation(pcl::PointCloud<pcl::PointXYZ>&, Eigen::Matrix<float, 4, 4, 0, 4, 4> const&) (in /home/riy2rng/Documents/ros/myslam_catkin_ws/devel/lib/myslam/ScanMatcher)
==173658== by 0x2C57DA: pcl::Registration<pcl::PointXYZ, pcl::PointXYZ, float>::align(pcl::PointCloud<pcl::PointXYZ>&, Eigen::Matrix<float, 4, 4, 0, 4, 4> const&) (in /home/riy2rng/Documents/ros/myslam_catkin_ws/devel/lib/myslam/ScanMatcher)
==173658== by 0x2C22FC: myslam::ScanMatcher::match(myslam_msgs::PointCloudScanMatcherRequest_<std::allocator<void> >&, myslam_msgs::PointCloudScanMatcherResponse_<std::allocator<void> >&) (in /home/riy2rng/Documents/ros/myslam_catkin_ws/devel/lib/myslam/ScanMatcher)
==173658== by 0x2E05DF: boost::_mfi::mf2<bool, myslam::ScanMatcher, myslam_msgs::PointCloudScanMatcherRequest_<std::allocator<void> >&, myslam_msgs::PointCloudScanMatcherResponse_<std::allocator<void> >&>::operator()(myslam::ScanMatcher*, myslam_msgs::PointCloudScanMatcherRequest_<std::allocator<void> >&, myslam_msgs::PointCloudScanMatcherResponse_<std::allocator<void> >&) const (in /home/riy2rng/Documents/ros/myslam_catkin_ws/devel/lib/myslam/ScanMatcher)
==173658== by 0x2DD571: bool boost::_bi::list3<boost::_bi::value<myslam::ScanMatcher*>, boost::arg<1>, boost::arg<2> >::operator()<bool, boost::_mfi::mf2<bool, myslam::ScanMatcher, myslam_msgs::PointCloudScanMatcherRequest_<std::allocator<void> >&, myslam_msgs::PointCloudScanMatcherResponse_<std::allocator<void> >&>, boost::_bi::rrlist2<myslam_msgs::PointCloudScanMatcherRequest_<std::allocator<void> >&, myslam_msgs::PointCloudScanMatcherResponse_<std::allocator<void> >&> >(boost::_bi::type<bool>, boost::_mfi::mf2<bool, myslam::ScanMatcher, myslam_msgs::PointCloudScanMatcherRequest_<std::allocator<void> >&, myslam_msgs::PointCloudScanMatcherResponse_<std::allocator<void> >&>&, boost::_bi::rrlist2<myslam_msgs::PointCloudScanMatcherRequest_<std::allocator<void> >&, myslam_msgs::PointCloudScanMatcherResponse_<std::allocator<void> >&>&, long) (in /home/riy2rng/Documents/ros/myslam_catkin_ws/devel/lib/myslam/ScanMatcher)
==173658== by 0x2DA6D0: bool boost::_bi::bind_t<bool, boost::_mfi::mf2<bool, myslam::ScanMatcher, myslam_msgs::PointCloudScanMatcherRequest_<std::allocator<void> >&, myslam_msgs::PointCloudScanMatcherResponse_<std::allocator<void> >&>, boost::_bi::list3<boost::_bi::value<myslam::ScanMatcher*>, boost::arg<1>, boost::arg<2> > >::operator()<myslam_msgs::PointCloudScanMatcherRequest_<std::allocator<void> >&, myslam_msgs::PointCloudScanMatcherResponse_<std::allocator<void> >&>(myslam_msgs::PointCloudScanMatcherRequest_<std::allocator<void> >&, myslam_msgs::PointCloudScanMatcherResponse_<std::allocator<void> >&) (in /home/riy2rng/Documents/ros/myslam_catkin_ws/devel/lib/myslam/ScanMatcher)
==173658== by 0x2D73D5: boost::detail::function::function_obj_invoker2<boost::_bi::bind_t<bool, boost::_mfi::mf2<bool, myslam::ScanMatcher, myslam_msgs::PointCloudScanMatcherRequest_<std::allocator<void> >&, myslam_msgs::PointCloudScanMatcherResponse_<std::allocator<void> >&>, boost::_bi::list3<boost::_bi::value<myslam::ScanMatcher*>, boost::arg<1>, boost::arg<2> > >, bool, myslam_msgs::PointCloudScanMatcherRequest_<std::allocator<void> >&, myslam_msgs::PointCloudScanMatcherResponse_<std::allocator<void> >&>::invoke(boost::detail::function::function_buffer&, myslam_msgs::PointCloudScanMatcherRequest_<std::allocator<void> >&, myslam_msgs::PointCloudScanMatcherResponse_<std::allocator<void> >&) (in /home/riy2rng/Documents/ros/myslam_catkin_ws/devel/lib/myslam/ScanMatcher)
==173658== by 0x2EC884: boost::function2<bool, myslam_msgs::PointCloudScanMatcherRequest_<std::allocator<void> >&, myslam_msgs::PointCloudScanMatcherResponse_<std::allocator<void> >&>::operator()(myslam_msgs::PointCloudScanMatcherRequest_<std::allocator<void> >&, myslam_msgs::PointCloudScanMatcherResponse_<std::allocator<void> >&) const (in /home/riy2rng/Documents/ros/myslam_catkin_ws/devel/lib/myslam/ScanMatcher)
==173658== by 0x2E9CEC: ros::ServiceSpec<myslam_msgs::PointCloudScanMatcherRequest_<std::allocator<void> >, myslam_msgs::PointCloudScanMatcherResponse_<std::allocator<void> > >::call(boost::function<bool (myslam_msgs::PointCloudScanMatcherRequest_<std::allocator<void> >&, myslam_msgs::PointCloudScanMatcherResponse_<std::allocator<void> >&)> const&, ros::ServiceSpecCallParams<myslam_msgs::PointCloudScanMatcherRequest_<std::allocator<void> >, myslam_msgs::PointCloudScanMatcherResponse_<std::allocator<void> > >&) (in /home/riy2rng/Documents/ros/myslam_catkin_ws/devel/lib/myslam/ScanMatcher)
==173658== Address 0x0 is not stack'd, malloc'd or (recently) free'd
==173658==
==173658==
==173658== Process terminating with default action of signal 11 (SIGSEGV)
==173658== Access not within mapped region at address 0x0
==173658== at 0x491C969: pcl::KdTreeFLANN<pcl::PointXYZ, flann::L2_Simple<float> >::radiusSearch(pcl::PointXYZ const&, double, std::vector<int, std::allocator<int> >&, std::vector<float, std::allocator<float> >&, unsigned int) const (in /home/riy2rng/.conda/envs/mamba/envs/myenv/lib/libpcl_kdtree.so.1.12.0)
==173658== by 0x2EF420: pcl::VoxelGridCovariance<pcl::PointXYZ>::radiusSearch(pcl::PointXYZ const&, double, std::vector<pcl::VoxelGridCovariance<pcl::PointXYZ>::Leaf const*, std::allocator<pcl::VoxelGridCovariance<pcl::PointXYZ>::Leaf const*> >&, std::vector<float, std::allocator<float> >&, unsigned int) const (in /home/riy2rng/Documents/ros/myslam_catkin_ws/devel/lib/myslam/ScanMatcher)
==173658== by 0x2EB074: pcl::NormalDistributionsTransform<pcl::PointXYZ, pcl::PointXYZ>::computeDerivatives(Eigen::Matrix<double, 6, 1, 0, 6, 1>&, Eigen::Matrix<double, 6, 6, 0, 6, 6>&, pcl::PointCloud<pcl::PointXYZ> const&, Eigen::Matrix<double, 6, 1, 0, 6, 1> const&, bool) (in /home/riy2rng/Documents/ros/myslam_catkin_ws/devel/lib/myslam/ScanMatcher)
==173658== by 0x2E8B42: pcl::NormalDistributionsTransform<pcl::PointXYZ, pcl::PointXYZ>::computeTransformation(pcl::PointCloud<pcl::PointXYZ>&, Eigen::Matrix<float, 4, 4, 0, 4, 4> const&) (in /home/riy2rng/Documents/ros/myslam_catkin_ws/devel/lib/myslam/ScanMatcher)
==173658== by 0x2C57DA: pcl::Registration<pcl::PointXYZ, pcl::PointXYZ, float>::align(pcl::PointCloud<pcl::PointXYZ>&, Eigen::Matrix<float, 4, 4, 0, 4, 4> const&) (in /home/riy2rng/Documents/ros/myslam_catkin_ws/devel/lib/myslam/ScanMatcher)
==173658== by 0x2C22FC: myslam::ScanMatcher::match(myslam_msgs::PointCloudScanMatcherRequest_<std::allocator<void> >&, myslam_msgs::PointCloudScanMatcherResponse_<std::allocator<void> >&) (in /home/riy2rng/Documents/ros/myslam_catkin_ws/devel/lib/myslam/ScanMatcher)
==173658== by 0x2E05DF: boost::_mfi::mf2<bool, myslam::ScanMatcher, myslam_msgs::PointCloudScanMatcherRequest_<std::allocator<void> >&, myslam_msgs::PointCloudScanMatcherResponse_<std::allocator<void> >&>::operator()(myslam::ScanMatcher*, myslam_msgs::PointCloudScanMatcherRequest_<std::allocator<void> >&, myslam_msgs::PointCloudScanMatcherResponse_<std::allocator<void> >&) const (in /home/riy2rng/Documents/ros/myslam_catkin_ws/devel/lib/myslam/ScanMatcher)
==173658== by 0x2DD571: bool boost::_bi::list3<boost::_bi::value<myslam::ScanMatcher*>, boost::arg<1>, boost::arg<2> >::operator()<bool, boost::_mfi::mf2<bool, myslam::ScanMatcher, myslam_msgs::PointCloudScanMatcherRequest_<std::allocator<void> >&, myslam_msgs::PointCloudScanMatcherResponse_<std::allocator<void> >&>, boost::_bi::rrlist2<myslam_msgs::PointCloudScanMatcherRequest_<std::allocator<void> >&, myslam_msgs::PointCloudScanMatcherResponse_<std::allocator<void> >&> >(boost::_bi::type<bool>, boost::_mfi::mf2<bool, myslam::ScanMatcher, myslam_msgs::PointCloudScanMatcherRequest_<std::allocator<void> >&, myslam_msgs::PointCloudScanMatcherResponse_<std::allocator<void> >&>&, boost::_bi::rrlist2<myslam_msgs::PointCloudScanMatcherRequest_<std::allocator<void> >&, myslam_msgs::PointCloudScanMatcherResponse_<std::allocator<void> >&>&, long) (in /home/riy2rng/Documents/ros/myslam_catkin_ws/devel/lib/myslam/ScanMatcher)
==173658== by 0x2DA6D0: bool boost::_bi::bind_t<bool, boost::_mfi::mf2<bool, myslam::ScanMatcher, myslam_msgs::PointCloudScanMatcherRequest_<std::allocator<void> >&, myslam_msgs::PointCloudScanMatcherResponse_<std::allocator<void> >&>, boost::_bi::list3<boost::_bi::value<myslam::ScanMatcher*>, boost::arg<1>, boost::arg<2> > >::operator()<myslam_msgs::PointCloudScanMatcherRequest_<std::allocator<void> >&, myslam_msgs::PointCloudScanMatcherResponse_<std::allocator<void> >&>(myslam_msgs::PointCloudScanMatcherRequest_<std::allocator<void> >&, myslam_msgs::PointCloudScanMatcherResponse_<std::allocator<void> >&) (in /home/riy2rng/Documents/ros/myslam_catkin_ws/devel/lib/myslam/ScanMatcher)
==173658== by 0x2D73D5: boost::detail::function::function_obj_invoker2<boost::_bi::bind_t<bool, boost::_mfi::mf2<bool, myslam::ScanMatcher, myslam_msgs::PointCloudScanMatcherRequest_<std::allocator<void> >&, myslam_msgs::PointCloudScanMatcherResponse_<std::allocator<void> >&>, boost::_bi::list3<boost::_bi::value<myslam::ScanMatcher*>, boost::arg<1>, boost::arg<2> > >, bool, myslam_msgs::PointCloudScanMatcherRequest_<std::allocator<void> >&, myslam_msgs::PointCloudScanMatcherResponse_<std::allocator<void> >&>::invoke(boost::detail::function::function_buffer&, myslam_msgs::PointCloudScanMatcherRequest_<std::allocator<void> >&, myslam_msgs::PointCloudScanMatcherResponse_<std::allocator<void> >&) (in /home/riy2rng/Documents/ros/myslam_catkin_ws/devel/lib/myslam/ScanMatcher)
==173658== by 0x2EC884: boost::function2<bool, myslam_msgs::PointCloudScanMatcherRequest_<std::allocator<void> >&, myslam_msgs::PointCloudScanMatcherResponse_<std::allocator<void> >&>::operator()(myslam_msgs::PointCloudScanMatcherRequest_<std::allocator<void> >&, myslam_msgs::PointCloudScanMatcherResponse_<std::allocator<void> >&) const (in /home/riy2rng/Documents/ros/myslam_catkin_ws/devel/lib/myslam/ScanMatcher)
==173658== by 0x2E9CEC: ros::ServiceSpec<myslam_msgs::PointCloudScanMatcherRequest_<std::allocator<void> >, myslam_msgs::PointCloudScanMatcherResponse_<std::allocator<void> > >::call(boost::function<bool (myslam_msgs::PointCloudScanMatcherRequest_<std::allocator<void> >&, myslam_msgs::PointCloudScanMatcherResponse_<std::allocator<void> >&)> const&, ros::ServiceSpecCallParams<myslam_msgs::PointCloudScanMatcherRequest_<std::allocator<void> >, myslam_msgs::PointCloudScanMatcherResponse_<std::allocator<void> > >&) (in /home/riy2rng/Documents/ros/myslam_catkin_ws/devel/lib/myslam/ScanMatcher)
==173658== If you believe this happened as a result of a stack
==173658== overflow in your program's main thread (unlikely but
==173658== possible), you can try to increase the size of the
==173658== main thread stack using the --main-stacksize= flag.
==173658== The main thread stack size used in this run was 8388608.
==173658==
==173658== HEAP SUMMARY:
==173658== in use at exit: 298,107 bytes in 939 blocks
==173658== total heap usage: 25,701 allocs, 24,762 frees, 45,506,667 bytes allocated
==173658==
==173658== LEAK SUMMARY:
==173658== definitely lost: 0 bytes in 0 blocks
==173658== indirectly lost: 0 bytes in 0 blocks
==173658== possibly lost: 66,752 bytes in 12 blocks
==173658== still reachable: 231,355 bytes in 927 blocks
==173658== suppressed: 0 bytes in 0 blocks
==173658== Rerun with --leak-check=full to see details of leaked memory
==173658==
==173658== For lists of detected and suppressed errors, rerun with: -s
==173658== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0)
Segmentation fault (core dumped)
Describe the bug
After calling align on an
NormalDistributionsTransformobject, I get a segfault somewhere deep inside the call stack (see below).Context
I'm trying to match successive point clouds using the NDT. The NDT is used in the callback function of a ROS service. Every time the callback function executes, I instantiate a
NormalDistributionsTransform<pcl::PointXYZ, pcl::PointXYZ>, set the source and target point clouds and execute the align method. This seems to work the first four or five times but then suddenly I get a segfault and the node crashes.Expected behavior
NDT shouldn't segfault, especially because it seems to work for a while before the issue occurs.
Current Behavior
Repeated calls to NDT cause segfault somewhere deep inside the call stack.
To Reproduce
See code below, it's rather straightforward, just repeatedly call NDT.
Screenshots/Code snippets
Your Environment (please complete the following information):
Possible Solution
Sorry, no idea
Additional context
There seems to be a similar bug #4944, but I'm not sure I understand their solution.