史诗级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

相关推荐
石头wang1 天前
onenote千年老bug,字体bug (calibri&微软雅黑) 的解决
microsoft·bug·onenote
林林要一直努力4 天前
AOSP Settings模块问题初窥
android·学习·bug·android studio
福大大架构师每日一题5 天前
redis 8.0.3版本更新详解:安全修复、新特性与关键bug修复全面解析
redis·安全·bug
杨小扩7 天前
特别放送:关于一个无法修复的系统级Bug
程序人生·bug
千帐灯无此声7 天前
Linux 测开:日志分析 + 定位 Bug
linux·c语言·c++·bug
紫璨月10 天前
rabbitMQ读取不到ThreadLocal消息的bug
rabbitmq·bug·java-rabbitmq
zzc92111 天前
Adobe Illustrator设置的颜色和显示的颜色不对应问题
adobe·bug·illustrator·错误·配色·透明度·底色
开-悟14 天前
嵌入式编程-使用AI查找BUG的启发
c语言·人工智能·嵌入式硬件·bug
一入JAVA毁终身14 天前
Data的时区格式BUG
bug
一入JAVA毁终身15 天前
处理Lombok的一个小BUG
java·开发语言·bug