pcl icon indicating copy to clipboard operation
pcl copied to clipboard

[apps] pcl_visualizer segfaults on PCDs written from PointXYZI clouds converted to PCLPointCloud2

Open themightyoarfish opened this issue 3 years ago • 1 comments

Describe the bug

When converting a PointCloud<PointXYZI> to PCLPointCloud2 and then applying savePCDFile(binary=true) to that, clouds are saved with header such as this:

# .PCD v0.7 - Point Cloud Data file format
VERSION 0.7
FIELDS x y z _ intensity _
SIZE 4 4 4 1 4 1
TYPE F F F U F U
COUNT 1 1 1 4 1 12
WIDTH 2048
HEIGHT 128
VIEWPOINT 0 0 0 1 0 0 0
POINTS 262144
DATA binary

invalid _ fields are placed into the data with seemingly nonsensical COUNTs. Trying to point-pick with pcl_viewer segfaults with

Multidimensional field found: _
Segmentation fault: 11

It tries to interpret those channels as some histogram type I think, but didn't check further. But the real issue seems to be that at least binary PCDs are corrupted with this method.

Context

Trying to apply savePCDFile() to blobs which can have different fields, and being able to use pcl_viewer with the resulting PCDs

Expected behavior

No invalid fields are inserted by PCDWriter::write().

Current Behavior

Invalid fields with name _ are inserted into the output.

To Reproduce

Something like this saves the pcd files:

  // cloud = PointCloud<PointXYZI>() …
  PCLPointCloud2 blob;
  toPCLPointCloud2(cloud, blob);
  io::savePCDFile(path, blob, Eigen::Vector4f::Zero(),
                            Eigen::Quaternionf::Identity(), binary

Your Environment (please complete the following information):

  • OS: Ubuntu 20.04 (writing), macOs 12.4 (pcl_viewer)
  • Compiler: gcc 9.4.0, clang 12.0
  • PCL Version 578b18b524 (both systems)

themightyoarfish avatar Sep 21 '22 16:09 themightyoarfish

The _ fields are not placed there by accident or by error -- they represent padding. After x, y, z, there are 4 bytes of padding to reach 16 bytes, and after intensity another 12 bytes, to reach 32 bytes in total. See also https://github.com/PointCloudLibrary/pcl/issues/4939 Also, if you write the cloud directly without toPCLPointCloud2, e.g. with savePCDFileBinary, there should be no _ fields in the PCD files. But the pcl_viewer should still be able to handle that, I will look into it.

mvieth avatar Sep 21 '22 18:09 mvieth