Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ndt/filter] call pcl::NormalDistributionsTransform::setInputTarget twice got segfault #4944

Closed
marf-cn opened this issue Sep 15, 2021 · 9 comments
Labels

Comments

@marf-cn
Copy link

marf-cn commented Sep 15, 2021

Describe the bug

A clear and concise description of what the bug is.
got segfault when calling pcl::NormalDistributionsTransform::setInputTarget second time.

Context

What are you trying to accomplish? Providing context helps us come up with a solution that is most useful in the real world

Expected behavior

A clear and concise description of what you expected to happen.

Current Behavior

What happens instead of the expected behavior?

To Reproduce

chang the map and call
pcl::NormalDistributionsTransform::setInputTarget
again
static pcl::NormalDistributionsTransform<pcl::PointXYZI, pcl::PointXYZI> ndt;
.......
ndt.setTransformationEpsilon(trans_eps);
ndt.setStepSize(step_size);
ndt.setResolution(ndt_res);
ndt.setMaximumIterations(max_iter);
ndt.setInputSource(filtered_scan_ptr);
ndt.setInputTarget(map_ptr1);
ndt.align(*output_cloud, init_guess);
....
ndt.setTransformationEpsilon(trans_eps);
ndt.setStepSize(step_size);
ndt.setResolution(ndt_res);
ndt.setMaximumIterations(max_iter);
ndt.setInputSource(filtered_scan_ptr);
ndt.setInputTarget(map_ptr2); //got segfault

Provide a link to a live example, or an unambiguous set of steps to reproduce this bug. A reproducible example helps to provide faster answers.

Screenshots/Code snippets
#0 0x00007fffe8e2ea6d in free () from /lib/x86_64-linux-gnu/libc.so.6
#1 0x00005555555ca47f in Eigen::internal::handmade_aligned_free(void*) ()
#2 0x00005555555ca4db in Eigen::internal::aligned_free(void*) ()
#3 0x00005555555ccd7d in void Eigen::internal::conditional_aligned_free(void*) ()
#4 0x00005555555d2420 in void Eigen::internal::conditional_aligned_delete_auto<float, true>(float*, unsigned long) ()
#5 0x00005555555cd19d in Eigen::DenseStorage<float, -1, -1, 1, 0>::~DenseStorage() ()
#6 0x00005555555cb578 in Eigen::PlainObjectBase<Eigen::Matrix<float, -1, 1, 0, -1, 1> >::~PlainObjectBase() ()
#7 0x00005555555cb594 in Eigen::Matrix<float, -1, 1, 0, -1, 1>::~Matrix() ()
#8 0x00005555555f145c in pcl::VoxelGridCovariancepcl::PointXYZ::Leaf::~Leaf() ()
#9 0x00005555555f147c in std::pair<unsigned long const, pcl::VoxelGridCovariancepcl::PointXYZ::Leaf>::~pair() ()
#10 0x00005555555f149c in void __gnu_cxx::new_allocator<std::_Rb_tree_node<std::pair<unsigned long const, pcl::VoxelGridCovariancepcl::PointXYZ::Leaf> > >::destroy<std::pair<unsigned long const, pcl::VoxelGridCovariancepcl::PointXYZ::Leaf> >(std::pair<unsigned long const, pcl::VoxelGridCovariancepcl::PointXYZ::Leaf>) ()
#11 0x00005555555ecc6f in void std::allocator_traits<std::allocator<std::_Rb_tree_node<std::pair<unsigned long const, pcl::VoxelGridCovariancepcl::PointXYZ::Leaf> > > >::destroy<std::pair<unsigned long const, pcl::VoxelGridCovariancepcl::PointXYZ::Leaf> >(std::allocator<std::_Rb_tree_node<std::pair<unsigned long const, pcl::VoxelGridCovariancepcl::PointXYZ::Leaf> > >&, std::pair<unsigned long const, pcl::VoxelGridCovariancepcl::PointXYZ::Leaf>
) ()
#12 0x00005555555e882d in std::_Rb_tree<unsigned long, std::pair<unsigned long const, pcl::VoxelGridCovariancepcl::PointXYZ::Leaf>, std::_Select1st<std::pair<unsigned long const, pcl::VoxelGridCovariancepcl::PointXYZ::Leaf> >, std::less, std::allocator<std::pair<unsigned long const, pcl::VoxelGridCovariancepcl::PointXYZ::Leaf> > >::_M_destroy_node(std::_Rb_tree_node<std::pair<unsigned long const, pcl::VoxelGridCovariancepcl::PointXYZ::Leaf> >) ()
#13 0x00005555555e355d in std::_Rb_tree<unsigned long, std::pair<unsigned long const, pcl::VoxelGridCovariancepcl::PointXYZ::Leaf>, std::_Select1st<std::pair<unsigned long const, pcl::VoxelGridCovariancepcl::PointXYZ::Leaf> >, std::less, std::allocator<std::pair<unsigned long const, pcl::VoxelGridCovariancepcl::PointXYZ::Leaf> > >::_M_drop_node(std::_Rb_tree_node<std::pair<unsigned long const, pcl::VoxelGridCovariancepcl::PointXYZ::Leaf> >
) ()
#14 0x00005555555dafea in std::_Rb_tree<unsigned long, std::pair<unsigned long const, pcl::VoxelGridCovariancepcl::PointXYZ::Leaf>, std::_Select1st<std::pair<unsigned long const, pcl::VoxelGridCovariancepcl::PointXYZ::Leaf> >, std::less, std::allocator<std::pair<unsigned long const, pcl::VoxelGridCovariancepcl::PointXYZ::Leaf> > >::_M_erase(std::_Rb_tree_node<std::pair<unsigned long const, pcl::VoxelGridCovariancepcl::PointXYZ::Leaf> >) ()
#15 0x00005555555dafc7 in std::_Rb_tree<unsigned long, std::pair<unsigned long const, pcl::VoxelGridCovariancepcl::PointXYZ::Leaf>, std::_Select1st<std::pair<unsigned long const, pcl::VoxelGridCovariancepcl::PointXYZ::Leaf> >, std::less, std::allocator<std::pair<unsigned long const, pcl::VoxelGridCovariancepcl::PointXYZ::Leaf> > >::_M_erase(std::_Rb_tree_node<std::pair<unsigned long const, pcl::VoxelGridCovariancepcl::PointXYZ::Leaf> >
) ()
#16 0x00005555555dafc7 in std::_Rb_tree<unsigned long, std::pair<unsigned long const, pcl::VoxelGridCovariancepcl::PointXYZ::Leaf>, std::_Select1st<std::pair<unsigned long const, pcl::VoxelGridCovariancepcl::PointXYZ::Leaf> >, std::less, std::allocator<std::pair<unsigned long const, pcl::VoxelGridCovariancepcl::PointXYZ::Leaf> > >::_M_erase(std::_Rb_tree_node<std::pair<unsigned long const, pcl::VoxelGridCovariancepcl::PointXYZ::Leaf> >) ()
#17 0x00005555555dafc7 in std::_Rb_tree<unsigned long, std::pair<unsigned long const, pcl::VoxelGridCovariancepcl::PointXYZ::Leaf>, std::_Select1st<std::pair<unsigned long const, pcl::VoxelGridCovariancepcl::PointXYZ::Leaf> >, std::less, std::allocator<std::pair<unsigned long const, pcl::VoxelGridCovariancepcl::PointXYZ::Leaf> > >::_M_erase(std::_Rb_tree_node<std::pair<unsigned long const, pcl::VoxelGridCovariancepcl::PointXYZ::Leaf> >
) ()
#18 0x00005555555dafc7 in std::_Rb_tree<unsigned long, std::pair<unsigned long const, pcl::VoxelGridCovariancepcl::PointXYZ::Leaf>, std::_Select1st<std::pair<unsigned long const, pcl::VoxelGridCovariancepcl::PointXYZ::Leaf> >, std::less, std::allocator<std::pair<unsigned long const, pcl::VoxelGridCovariancepcl::PointXYZ::Leaf> > >::_M_erase(std::_Rb_tree_node<std::pair<unsigned long const, pcl::VoxelGridCovariancepcl::PointXYZ::Leaf> >) ()
#19 0x00005555555dafc7 in std::_Rb_tree<unsigned long, std::pair<unsigned long const, pcl::VoxelGridCovariancepcl::PointXYZ::Leaf>, std::_Select1st<std::pair<unsigned long const, pcl::VoxelGridCovariancepcl::PointXYZ::Leaf> >, std::less, std::allocator<std::pair<unsigned long const, pcl::VoxelGridCovariancepcl::PointXYZ::Leaf> > >::_M_erase(std::_Rb_tree_node<std::pair<unsigned long const, pcl::VoxelGridCovariancepcl::PointXYZ::Leaf> >
) ()
#20 0x00005555555dafc7 in std::_Rb_tree<unsigned long, std::pair<unsigned long const, pcl::VoxelGridCovariancepcl::PointXYZ::Leaf>, std::_Select1st<std::pair<unsigned long const, pcl::VoxelGridCovariancepcl::PointXYZ::Leaf> >, std::less, std::allocator<std::pair<unsigned long const, pcl::VoxelGridCovariancepcl::PointXYZ::Leaf> > >::_M_erase(std::_Rb_tree_node<std::pair<unsigned long const, pcl::VoxelGridCovariancepcl::PointXYZ::Leaf> >) ()
#21 0x00005555555dafc7 in std::_Rb_tree<unsigned long, std::pair<unsigned long const, pcl::VoxelGridCovariancepcl::PointXYZ::Leaf>, std::_Select1st<std::pair<unsigned long const, pcl::VoxelGridCovariancepcl::PointXYZ::Leaf> >, std::less, std::allocator<std::pair<unsigned long const, pcl::VoxelGridCovariancepcl::PointXYZ::Leaf> > >::_M_erase(std::_Rb_tree_node<std::pair<unsigned long const, pcl::VoxelGridCovariancepcl::PointXYZ::Leaf> >
) ()
In order to help explain your problem, please consider adding

  • screenshots of the GUI issues
  • code snippets: syntax for code with correct language highlights

Your Environment (please complete the following information):

  • OS: [e.g. Ubuntu 18.04]
  • Compiler: [:eg GCC 8.1]
  • PCL Version [e.g. 1.10, HEAD]

Possible Solution
try putting PCL_MAKE_ALIGNED_OPERATOR_NEW in VoxelGridCovariance

class VoxelGridCovariance : public VoxelGrid
{
// public:
// PCL_MAKE_ALIGNED_OPERATOR_NEW
...
Not obligatory, but suggest a fix/reason for the bug. Feel free to create a PR if you feel comfortable.

Additional context

Add any other context about the problem here.

@marf-cn marf-cn added kind: bug Type of issue status: triage Labels incomplete labels Sep 15, 2021
@tin1254
Copy link
Contributor

tin1254 commented Sep 15, 2021

This is weird because in the call stack it tries to destroy Leaf, but by just calling setInputTarget it shouldn't happen.

We may need more context, can you provide us some runnable code to reproduce the error?

@mvieth
Copy link
Member

mvieth commented Sep 16, 2021

You suggest to add PCL_MAKE_ALIGNED_OPERATOR_NEW. Have you done that and it fixed the problem for you or is that just an idea?
Please fill out the rest of the issue template, or delete the lines that don't apply.

@mvieth mvieth added module: filters and removed status: triage Labels incomplete labels Sep 16, 2021
@marf-cn
Copy link
Author

marf-cn commented Sep 17, 2021

Yes, it fixed my problem.
Calling setInputTarget again may release target point cloud last time I set. Due to "TargetGrid target_cells_" in NormalDistributionsTransform is not aliged, it may happen.

You can reproduce the bug as fellowed:

pcl::NormalDistributionsTransform<pcl::PointXYZI, pcl::PointXYZI> ndt;
pcl::PointCloudpcl::PointXYZI map;
pcl::PointCloudpcl::PointXYZI::Ptr cloud(new pcl::PointCloudpcl::PointXYZI);
Eigen::Matrix4f loc(Eigen::Matrix4f::Identity()) = Eigen::Matrix4f::Identity();

const std::vectorstd::string pcd_paths = {std::string(1.pcd),std::string(2.pcd),std::string(3.pcd),std::string(4.pcd)};

bool is_map_init = false;
bool is_reload_map = false;
for (int i=0; i<pcd_paths.size(); i++){
pcl::PointCloudpcl::PointXYZI::Ptr transformed_cloud(new pcl::PointCloudpcl::PointXYZI());
pcl::io::loadPCDFilepcl::PointXYZI(pcd_paths[i], *cloud);

if(!is_map_init ){
pcl::transformPointCloud(*cloud, *transformed_cloud, loc);
map += *transformed_cloud;
is_map_init = true;
continue;
}

pcl::VoxelGridpcl::PointXYZI voxel_grid_filter;
voxel_grid_filter.setLeafSize(1.0,1.0,1.0);
voxel_grid_filter.setInputCloud(cloud);
voxel_grid_filter.filter(*filtered_scan_ptr);

pcl::PointCloudpcl::PointXYZI::Ptr map_ptr(new pcl::PointCloudpcl::PointXYZI(map));

ndt.setTransformationEpsilon(0.01);
ndt.setStepSize(0.1);
ndt.setResolution(0.1);
ndt.setMaximumIterations(10);
ndt.setInputSource(filtered_scan_ptr);
if(is_reload_map)
ndt.setInputTarget(map_ptr);

double fitness_score = ndt.getFitnessScore();
loc= ndt.getFinalTransformation();

if(fitness_score < 0.5){
pcl::transformPointCloud(*cloud, *transformed_cloud, loc);
map += *transformed_cloud;
is_reload_map = true;
}
}

@marf-cn marf-cn closed this as completed Sep 18, 2021
@tin1254
Copy link
Contributor

tin1254 commented Sep 19, 2021

@mvieth Overall it makes sense to me to add PCL_MAKE_ALIGNED_OPERATOR_NEW even without reproducing it, what do you think? @mvieth

@mvieth
Copy link
Member

mvieth commented Sep 20, 2021

But the trace suggests that the segfault happens while destroying a leaf, so why would adding PCL_MAKE_ALIGNED_OPERATOR_NEW to VoxelGridCovariance prevent that?
Also: Adding that macro is necessary for fixed-size Eigen types, but not dynamic-size types. However, the type in the trace is a dynamic-size type (recognizable by the -1 in the template list).
Plus I can't reproduce the error with the given code. If I had to guess what made the code first not work, then work, I would guess luck/bad luck or a case of not enabling SIMD extensions (e.g. -mavx)

@marf-cn
Copy link
Author

marf-cn commented Sep 23, 2021

There are some fixed-size Eigen types in struct Leaf which is included in class VoxelGridCovariance . Is it the cause?

@marf-cn
Copy link
Author

marf-cn commented Sep 23, 2021

" not enabling SIMD extensions" may be the cause, I'll try later。

@tin1254
Copy link
Contributor

tin1254 commented Sep 26, 2021

There are some fixed-size Eigen types in struct Leaf which is included in class VoxelGridCovariance . Is it the cause?

I also doubted that but as @mvieth said, the trace indicating it was caused by dynamic size matrix, which adding PCL_MAKE_ALIGNED_OPERATOR_NEW only solves issues with fixed size matrix

@marf-cn Since you close the issue, have you fixed your issue already?

@marf-cn
Copy link
Author

marf-cn commented Apr 29, 2022

@mvieth Yes,I fixed my issue by adding PCL_MAKE_ALIGNED_OPERATOR_NEW temporarily! I haven't dig into the issue if SIMD worked, due to I have quited from the project.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants