PointCloudLibrary / pcl

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

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

Open StefanFabian opened 1 month ago

StefanFabian commented 1 month ago

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):

Possible Solution

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

larshg commented 1 month ago

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?

StefanFabian commented 1 month ago

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.

mvieth commented 1 month ago

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.