pcl icon indicating copy to clipboard operation
pcl copied to clipboard

Crashes on Ubuntu 24 when using minimum C++17 and expecting Eigen to not require explicit alignment anymore

Open StefanFabian opened this issue 1 year ago • 3 comments

Context

Since C++17 Eigen does not require custom alignment handling anymore. Since ROS 2 Humble, C++17 has been the default, and at this time, support can be expected for new software.

Expected behavior

To be able to use Eigen without using the macros to create custom alignment for structs such as EIGEN_MAKE_ALIGNED_OPERATOR_NEW.

Current Behavior

This will crash because #5793 disabled the automatic Eigen check to disable the need for custom-aligned allocation. This results in the destructors of classes/structs containing Eigen members but not the EIGEN_MAKE_ALIGNED_OPERATOR_NEW macro (which is not needed for >=C++17) crashing when trying to free the memory. E.g. with a

free(): invalid next size (normal)                                                                                          
Aborted (core dumped)

This is especially annoying since fixing this on the user side would require adding the macro in every class that directly or by inheritance contains eigen members and using the custom stl container allocators for any such class. A practice that is cumbersome and error-prone.

Your Environment (please complete the following information):

  • OS: Ubuntu 24
  • Compiler: [:eg GCC 8.1]
  • PCL Version libpcl-dev (1.14)

Possible Solution

Setting the CXX standard to 17 (in general or for releases >=Ubuntu 22)

StefanFabian avatar Sep 06 '24 08:09 StefanFabian

Its because you want to use apt installed PCL, which I assume is build with c++14, in a c++17 project, that you encounter the error? As an alternative you can just compile PCL from source with c++17 enabled? Then its not added according to #5793?

larshg avatar Sep 06 '24 10:09 larshg

Yes, I use an apt-installed PCL. The problem with compiling from source is that apt updates would probably overwrite a global installation, and I can't uninstall the apt package because other packages depend on it. And especially when using it in a plugin, this would just be asking for trouble.

StefanFabian avatar Sep 06 '24 11:09 StefanFabian

One thing you can try is making use of PCL_NO_PRECOMPILE: https://pcl.readthedocs.io/projects/tutorials/en/master/adding_custom_ptype.html#how-to-add-a-new-pointt-type The effect is that PCL's templated classes will be compiled together with your own code, with the same settings. Whether this fixes the problem also depends on what you use from PCL.

This is especially annoying since fixing this on the user side would require adding the macro in every class that directly or by inheritance contains eigen members and using the custom stl container allocators for any such class. A practice that is cumbersome and error-prone.

Out of interest, how many classes would this be? Are these classes that use Eigen, but are unrelated to PCL?

The problem with compiling from source is that apt updates would probably overwrite a global installation

The PCL apt packages for a specific Ubuntu release will very likely not receive any update, at least this was, to my knowledge, never the case in the past. So on Ubuntu 24.04, you will e.g. not get PCL 1.15 (which is not yet released anyway), as a Ubuntu release keeps the software versions fixed, and only applies important security fixes for some packages (as far as I know). If you build PCL from source, it will by the way be installed in a different location (/usr/local) than the apt version, at least by default.

And especially when using it in a plugin, this would just be asking for trouble.

Not sure what you mean? What kind of plugin?

Setting the CXX standard to 17 (in general

I am willing to discuss such a change, but since you will not get a different PCL version via apt on Ubuntu 24.04, this would be irrelevant for you. By the way, we, the PCL maintainers, are not directly responsible for the apt packages and which setting are used while building PCL for the packages.

mvieth avatar Sep 08 '24 14:09 mvieth

From now on, PCL will be compiled as C++17 by default. This applies to the master branch and any future releases (so starting with PCL 1.15.0). However, as I explained above, I assume that apt packages in already released Ubuntu versions will not be updated to a newer PCL release. For any questions about the apt packages, please contact the maintainers of those packages.

mvieth avatar Dec 25 '24 13:12 mvieth