ethz-asl / segmap

A map representation based on 3D segments
BSD 3-Clause "New" or "Revised" License
1.06k stars 394 forks source link

Crash with region-growing segmenter #51

Closed Tacoma closed 6 years ago

Tacoma commented 6 years ago

Hi, I noticed that the segmentation crashes if no points are in the pointcloud. The log before the crash is:

I0822 12:45:54.641043 13327 region_growing_segmenter.cpp:54] Starting region growing segmentation.
I0822 12:45:54.641834 13327 region_growing_segmenter.cpp:62] Normals are computed.
I0822 12:45:54.641858 13327 region_growing_segmenter.cpp:73] Number of indices 0
I0822 12:45:54.641868 13327 region_growing_segmenter.cpp:74] Number of normals 2
[pcl::RegionGrowing::prepareForSegmentation] Empty given indices!
[pcl::KdTreeFLANN::setInputCloud] Cannot create a KDTree with an empty input cloud!
/opt/ros/indigo/lib/node_manager_fkie/respawn: line 8: 13143 Segmentation fault      (core dumped) stdbuf -i0 -oL -eL "$@"'

I avoided the crash by adding a check to the extraction in https://github.com/ethz-asl/segmatch/blob/master/segmatch/src/segmenters/region_growing_segmenter.cpp#L74

if (indices->size() > 0) {
      region_growing_estimator_.extract(clusters);
}
rdube commented 6 years ago

Thanks for catching this! Would you like to open a PR for fixing this? We could already return on that line if the cloud is empty: https://github.com/ethz-asl/segmatch/blob/master/segmatch/src/segmenters/region_growing_segmenter.cpp#L48

Tacoma commented 6 years ago

I'm not sure how to do it correctly, but I created a small fix. But we can only return after creating the indices, because the point-cloud itself might have points but they are all filtered later because of high curvature. At least that's why it crashed in my case. I'm not exactly sure where the crash occurs, as pcl notices twice that the indices are empty, but returning before the extraction solved the problem for me, so I guess it should be fine.