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

Crash on returning filtered pointcloud (Statisical or Radius) - AVX/SSE issue #6038

Open
geoeo opened this issue May 13, 2024 · 7 comments
Open
Labels
kind: bug Type of issue status: triage Labels incomplete

Comments

@geoeo
Copy link

geoeo commented May 13, 2024

Describe the bug

memory free error when using statistical outlier filter or radius outlier filter. Pass through works. This happens when either SSE or AVX are enabled

A clear and concise description of what the bug is.

When using the filters mentioned above to filter a point cloud the program crashes when the function returns on a memory free

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

Filter point clouds

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

The program does not crash

What happens instead of the expected behavior?

The program crashes

Screenshots/Code snippets

Setup:

WORKDIR /root
RUN apt update && apt install -y libeigen3-dev liblz4-dev libhdf5-dev libgl1-mesa-dev libboost-all-dev

RUN wget https://github.com/flann-lib/flann/archive/refs/tags/1.9.2.zip
RUN unzip 1.9.2.zip
RUN cd flann-1.9.2 && mkdir -p build && cd build \
&& cmake -DBUILD_CUDA_LIB=ON -DCMAKE_BUILD_TYPE=Release .. \
&& make -j $(nproc --all) && make install
RUN rm 1.9.2.zip

WORKDIR /root
RUN wget https://github.com/PointCloudLibrary/pcl/archive/refs/tags/pcl-1.14.1.zip
RUN unzip pcl-1.14.1.zip
RUN cd pcl-pcl-1.14.1 && mkdir -p build && cd build \
&& cmake -DBUILD_GPU=ON \
    -DWITH_PCAP=OFF \
    -DWITH_LIBUSB=OFF \
    -DWITH_VTK=OFF \
    #-DPCL_ENABLE_SSE=OFF \
    -DPCL_ENABLE_AVX=OFF \
    -DPCL_NO_PRECOMPILE=ON \
    -DCMAKE_CXX_STANDARD=17 \
    -DCMAKE_CUDA_STANDARD=17 \
    -DCMAKE_BUILD_TYPE=Release .. \
&& make -j $(nproc --all) && make install
RUN rm pcl-1.14.1.zip

Code:


pcl::PointCloud<pcl::PointXYZ>::Ptr DigitalSurfaceModel::filterPointCloud(const cv::Mat &points, float min_z, float max_z)
{
  assert(points.type() == CV_64F);
  assert(m_assumption == SurfaceAssumption::ELEVATION);

  LOG_F(INFO, "PCL size before filtering: %d", points.rows);
  pcl::PointCloud<pcl::PointXYZ>::Ptr point_cloud(new pcl::PointCloud<pcl::PointXYZ>);
  point_cloud->points.resize(points.rows);
  vector<int> indices(points.rows); 
  iota(indices.begin(), indices.end(), 0); 

  transform(execution::par_unseq,indices.begin(),indices.end(),point_cloud->points.begin(),[&points](const auto i)
  {
    return pcl::PointXYZ(
      static_cast<float>(points.at<double>(i,0)),
      static_cast<float>(points.at<double>(i,1)),
      static_cast<float>(points.at<double>(i,2))
    );
  });

  point_cloud->width = (int)point_cloud->points.size();
  point_cloud->height = 1;

  pcl::PointCloud<pcl::PointXYZ>::Ptr point_cloud_filtered(new pcl::PointCloud<pcl::PointXYZ>);
  
  // pcl::PassThrough<pcl::PointXYZ> pass;
  // pass.setInputCloud (point_cloud);
  // pass.setFilterFieldName ("z");
  // pass.setFilterLimits (min_z, max_z);
  // pass.setNegative (false);
  // pass.setKeepOrganized(false);
  // pass.filter (*point_cloud_filtered);

  // Seems to be a memory issue when returning a pointcloud filtered by sor?
  pcl::StatisticalOutlierRemoval<pcl::PointXYZ> sor;
  sor.setInputCloud (point_cloud);
  sor.setMeanK (20);
  sor.setStddevMulThresh (2.0);
  sor.setKeepOrganized(false);
  sor.filter (*point_cloud_filtered);

  // pcl::RadiusOutlierRemoval<pcl::PointXYZ> outrem;
  // outrem.setInputCloud(point_cloud);
  // outrem.setRadiusSearch(0.8);
  // outrem.setMinNeighborsInRadius (2);
  // outrem.setKeepOrganized(false);
  // outrem.filter (*point_cloud_filtered);

  LOG_F(INFO, "PCL size after filtering: %ld", point_cloud_filtered->points.size());
  return point_cloud_filtered; //<----- Crash on return
}

Your Environment (please complete the following information):

  • OS: Ubuntu 22.04
  • Compiler: GCC 11.4
  • PCL Version1.14.1 / (Also happens on 1.14.0)
  • Eigen 3.4.0
@geoeo geoeo added kind: bug Type of issue status: triage Labels incomplete labels May 13, 2024
@geoeo
Copy link
Author

geoeo commented May 13, 2024

Edit: It seems the culprit were AVX/SSE instructions. After I disabled them both on compilation it works!

@geoeo geoeo changed the title Crash on returning filtered pointcloud (Statisical or Radius) Crash on returning filtered pointcloud (Statisical or Radius) - AVX/SSE issue May 13, 2024
@mvieth
Copy link
Member

mvieth commented May 13, 2024

Hi, the thing with SSE and AVX is that the options used when compiling PCL should match the options used for your own project, otherwise problems can occur. Usually, CMake takes care of this (unless you do not use CMake for building your own project, edit: or you manually change SSE/AVX options in your own CMakeLists.txt). Enabling PCL_NO_PRECOMPILE also often makes these problems go away because more of PCL's code is compiled together with your own code, so SSE/AVX options are the same.
If you provide a backtrace, e.g. from gdb or valgrind, I can try to take a guess what exactly happens in your case.

@geoeo
Copy link
Author

geoeo commented May 13, 2024

@mvieth Will do. In another note: Could the problem we that I didnt compile eigen with AVX/SSE? I just installed via apt

@mvieth
Copy link
Member

mvieth commented May 13, 2024

@mvieth Will do. In another note: Could the problem we that I didnt compile eigen with AVX/SSE? I just installed via apt

Eigen is a header-only library, so there are no binaries installed. The classes and functions from Eigen are compiled when PCL and your own project are compiled.

@geoeo
Copy link
Author

geoeo commented May 13, 2024

Ok so I recompiled PCL in Debug mode with AVX and SSE on. And I am running my code in RelWithDebug. It doesnt seem to happen in Debug.

image

image

I think whats happening is that it tries to free the point_cloud data structure and somehow the filtering already consumes it? Sorry that I cant provide a more detailed trace

@mvieth
Copy link
Member

mvieth commented May 14, 2024

I think whats happening is that it tries to free the point_cloud data structure and somehow the filtering already consumes it? Sorry that I cant provide a more detailed trace

point_cloud_filtered is filled by the outlier removal filter, and point_cloud is only read from by the filter, so I don't think that's it.
Another thing: can you post your CMakeLists.txt? And run your program with valgrind? That might give us more information.

@geoeo
Copy link
Author

geoeo commented May 14, 2024

point_cloud is a scoped pcl that should be released when the functions returns.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind: bug Type of issue status: triage Labels incomplete
Projects
None yet
Development

No branches or pull requests

2 participants