2

I encountered a problem when I was using Eigen objects in my code. There is a class defined in my code:

class MyClass
{
public:
    EIGEN_MAKE_ALIGNED_OPERATOR_NEW
    MyClass();
    /*other member functions*/

private:
    float3 member_var;
    Eigen::Matrix4f pose;
    int id;
    /*......*/
};

As the code is shown above, if pose is not the first member variable in MyClass, e.g. after float3 member_var, the program got segmentation fault ( core dumped) error.

If I put Eigen::Matrix4f pose as the first member variable, there is no segfault error.

I checked the documentation of Eigen library about memory alignment issues, see here. It says that Eigen member variables are not required to be put at the beginning of the class.

I am wondering whether it is a bug from Eigen or my code?

fyl
  • 59
  • 7
  • documentations states that you need to specify `EIGEN_MAKE_ALIGNED_OPERATOR_NEW` and therefore create your `MyClass` via `new` operator. is that what you do? – d_kog Dec 09 '20 at 18:17
  • Hi, I have added `EIGEN_MAKE_ALIGNED_OPERATOR_NEW` in my code. It still fails. – fyl Dec 09 '20 at 19:08
  • Please add a minimal working example showing how `MyClass` is used and when this produces a segfault. – dtell Dec 10 '20 at 14:14
  • Were you using `make_shared`? If so, Eigen's aligned `new` overload isn't actually called: https://stackoverflow.com/questions/57929127/why-stdmake-shared-is-always-using-the-global-memory-allocation-even-with-cl – Julian Panetta Sep 07 '21 at 01:45

0 Answers0