PointCloudLibrary / pcl

Point Cloud Library (PCL)
https://pointclouds.org/
Other
9.84k stars 4.61k forks source link

[module_name] pcl 1.8 voxel filter: invalid pointer #4964

Closed HaisenbergPeng closed 2 years ago

HaisenbergPeng commented 2 years ago

Error in `./test': free(): invalid pointer: 0x0000000002001b80 Context

Please look at the code below. if using PCL 1.8, the error 'invalid point' comes out. However, if I move the code in function 'fun()' inside 'main()' or use PCL 1.7 intead, the error is gone. Anyone can explain it? I suspect it is the issue related to the smart pointer destruction.

#include<iostream>
#include<fstream>
#include<string>
#include<Eigen/Dense>
#include <pcl/filters/filter.h>
#include <pcl/filters/voxel_grid.h>
#include <pcl/point_cloud.h>
#include <pcl/point_types.h>
#include <pcl/io/pcd_io.h>
using namespace std;
// using namespace cv;
#define mSize 500
typedef pcl::PointXYZI PointType;
void changeAffine3f(Eigen::Affine3f a){
    a = Eigen::Affine3f::Identity();
}

void fun(){
        // this part of code cause 'invalid point in ALOAM KLOAM'
    pcl::PointCloud<PointType>::Ptr pc1(new pcl::PointCloud<PointType>());
    pcl::PointCloud<PointType>::Ptr pc2(new pcl::PointCloud<PointType>());
    pcl::io::loadPCDFile<PointType>("/media/binpeng/BIGLUCK/Datasets/LABdataset/Maps/IMR2ndFloor/map_pcd/trajectory.pcd",*pc1);
    pcl::VoxelGrid<PointType> vf;
    vf.setLeafSize(0.2,0.2,0.2);
    vf.setInputCloud(pc1);
    vf.filter(*pc2);
}
int main(){
    // test pcl
    fun();`
    return 0;
}

Your Environment (please complete the following information):

tin1254 commented 2 years ago

Can't reproduce the error with v1.9

I can't easily build v1.8 with my environment, maybe someone else could try

HaisenbergPeng commented 2 years ago

The error is gone with pcl1.7 and pcl1.9. For building pcl1.8 with other versions, please refer to this blog

mvieth commented 2 years ago

@HaisenbergPeng Can you run your program with valgrind or gdb (and do a backtrace)?

kunaltyagi commented 2 years ago

@HaisenbergPeng please try with pcl-1.12 as well. If it works, then this is a support request, and not a bug

HaisenbergPeng commented 2 years ago

@kunaltyagi yes, you are right, it is actually a support request.

The error is gone with pcl1.7 and pcl1.9. For building pcl1.8 with other versions, please refer to this blog

HaisenbergPeng commented 2 years ago

@mvieth sorry, I don't know how to debug with gdb. Could you kindly give an hint?

mvieth commented 2 years ago

This site or this site might help you, otherwise please use google or another search engine, there are many tutorials for gdb. Using valgrind is simply valgrind ./name_of_your_executable_program. Google etc. will also help you for further questions.

tin1254 commented 2 years ago

@HaisenbergPeng If you are using vscode, I would suggest using their official gdb plugin for better visualization. Tutorial in Chinese: link1 link2

mvieth commented 2 years ago

Closing this issue due to no response, and because there does not seem to be an issue in PCL (it works with PCL 1.7 and 1.9)