史诗级PCL和Eigen联合BUG

环境

系统:Ubuntu 18.04

PCL:1.8.1(系统默认)

Eigen:3.4.3(系统默认)


BUG

cpp 复制代码
Thread 1 "fastlio_sam_map" received signal SIGSEGV, Segmentation fault.
__GI___libc_free (mem=0x2c890) at malloc.c:3113
3113	malloc.c: 没有那个文件或目录.
(gdb) where
#0  __GI___libc_free (mem=0x2c890) at malloc.c:3113
#1  0x00005555555d7fdb in Eigen::internal::handmade_aligned_free (
    ptr=<optimized out>) at /usr/include/eigen3/Eigen/src/Core/util/Memory.h:98
#2  Eigen::internal::aligned_free (ptr=<optimized out>)
    at /usr/include/eigen3/Eigen/src/Core/util/Memory.h:179
#3  Eigen::aligned_allocator<pcl::PointXYZINormal>::deallocate (
    this=0x7fffd0016258, p=<optimized out>)
    at /usr/include/eigen3/Eigen/src/Core/util/Memory.h:747
#4  std::allocator_traits<Eigen::aligned_allocator<pcl::PointXYZINormal> >::deallocate (__a=..., __n=<optimized out>, __p=<optimized out>)
    at /usr/include/c++/7/bits/alloc_traits.h:328
#5  std::_Vector_base<pcl::PointXYZINormal, Eigen::aligned_allocator<pcl::PointXYZINormal> >::_M_deallocate (this=0x7fffd0016258, __n=<optimized out>, 
    __p=<optimized out>) at /usr/include/c++/7/bits/stl_vector.h:180
#6  std::_Vector_base<pcl::PointXYZINormal, Eigen::aligned_allocator<pcl::PointXYZINormal> >::~_Vector_base (this=0x7fffd0016258, __in_chrg=<optimized out>)
    at /usr/include/c++/7/bits/stl_vector.h:162
#7  std::vector<pcl::PointXYZINormal, Eigen::aligned_allocator<pcl::PointXYZINormal> >::~vector (this=0x7fffd0016258, __in_chrg=<optimized out>)
    at /usr/include/c++/7/bits/stl_vector.h:435
#8  pcl::PointCloud<pcl::PointXYZINormal>::~PointCloud (this=0x7fffd0016220, 
    __in_chrg=<optimized out>) at /usr/include/pcl-1.8/pcl/point_cloud.h:240
#9  pcl::PointCloud<pcl::PointXYZINormal>::~PointCloud (this=0x7fffd0016220, 

错误原因

这个bug,是在我运行SLAM算法,例如fast_lio_sam时遇到的。使用GDB调试后出现上面的报错,大致原因是Eigen在做PCL的析构的时候失败了,经过翻墙大量查阅资料发现,这是PCL和Eigen的一个版本共存的BUG,解决方法可以尝试更换PCL和Eigen版本,但是我担心破坏环境,因此采用另一种办法。


错误位置

sor的类型为你代码pcl::PointXYZI、pcl::PointXYZ等等等任意类型,只要一进入到滤波函数就会段错误,因此解决死路就是通过替换sor的类型为pcl::PointCloud2格式,进行滤波,滤波后再将点重新填入到pcl::PointXYZI格式的sor里面即可。

cpp 复制代码
sor.setInputcloud(*surfCloud);
sor.filter(*srufCloud);

代码对比

修改前:

cpp 复制代码
pcl::PointCloud<PointType>::Ptr cloud_temp(new pcl::PointCloud<PointType>());
downSizeFilterICP.setInputCloud(nearKeyframes);
downSizeFilterICP.filter(*cloud_temp);

修改后:

cpp 复制代码
pcl::PCLPointCloud2::Ptr cloud2(new pcl::PCLPointCloud2());
pcl::PCLPointCloud2::Ptr cloud_filtered2(new pcl::PCLPointCloud2());
pcl::PointCloud<PointType>::Ptr  cloud_temp (new pcl::PointCloud<PointType>);
pcl::toPCLPointCloud2(*nearKeyframes, *cloud2);
pcl::VoxelGrid<PointType> downSizeFilter2;
pcl::VoxelGrid<pcl::PCLPointCloud2> sor2;
sor2.setInputCloud(cloud2);
sor2.setLeafSize(mappingSurfLeafSize, mappingSurfLeafSize, mappingSurfLeafSize);
sor2.filter(*cloud_filtered2);
pcl::fromPCLPointCloud2(*cloud_filtered2, *cloud_temp);
downSizeFilterICP.setInputCloud(cloud_temp);

参考链接:
链接1链接2链接3链接4链接5链接6

相关推荐
东巴图19 小时前
分解如何利用c++修复小程序的BUG
开发语言·c++·bug
workflower3 天前
Fundamentals of Architectural Styles and patterns
开发语言·算法·django·bug·结对编程
lvchaoq4 天前
记录小程序真机bug,而模拟器无法复现
小程序·bug
喜欢便码4 天前
禅道提交bug的几种状态
bug
从前慢,现在也慢4 天前
(3)Bug篇
学习·bug·测试
西柚小萌新4 天前
【Bug:docker】--Docker国内镜像源加载失败
docker·容器·bug
初圣魔门首席弟子7 天前
c++ bug 记录(merge函数调用时错误地传入了vector对象而非迭代器。)
java·c++·bug
Qiuner7 天前
历劫波,明真我——Debug Commune
ai·开源·bug·debug·信息差·信息·交流
川石课堂软件测试9 天前
什么是BUG,你对BUG的了解有多少?
android·linux·服务器·python·功能测试·bug·安全性测试