[eigen] Alignment of derived matrix class

[ Thread Index | Date Index | More lists.tuxfamily.org/eigen Archives ]

Dear Eigen experts,

while porting some robotics matrix code to Eigen2 I have encountered the following problem
on QNX platform, but I do not think it is QNX specific.

I have the following class hierarchy, which I have created using guidelines from:

// Base class (with not copy-pasted robot-specific methods)
class A : public Eigen::Matrix<double, 6, 1> {
    // Copy constructor from any Eigen matrix type
    template<typename OtherDerived>
    A(const Eigen::MatrixBase<OtherDerived>& other)
        : BaseClass(other)

    // Reuse assignment operators from base class
    using BaseClass::operator=;


// Derived class type, which will hold additional methods
class B : public A {
    template<typename OtherDerived>
    B(const Eigen::MatrixBase<OtherDerived>& other)
        : Ft_v_vector(other)


When I run this code on Linux - it works just fine.
When I run this on QNX - it fails with Unalligned Array Assert. The backtrace is here:

#0  0xb033dad1 in SignalKill () from /usr/qnx641/target/qnx6/x86/lib/libc.so.3
#1  0xb032c82e in raise () from /usr/qnx641/target/qnx6/x86/lib/libc.so.3
#2  0xb032ab08 in abort () from /usr/qnx641/target/qnx6/x86/lib/libc.so.3
#3  0xb032ad29 in __assert () from /usr/qnx641/target/qnx6/x86/lib/libc.so.3
#4  0x080534ec in ei_matrix_array (this=0x7f42db4) at /opt/qnx641/target/qnx6/mrlib/include/eigen2/Eigen/src/Core/MatrixStorage.h:43
#5  0x0805350f in ei_matrix_storage (this=0x7f42db4) at /opt/qnx641/target/qnx6/mrlib/include/eigen2/Eigen/src/Core/MatrixStorage.h:79
#6  0x0809936f in Matrix<Eigen::CwiseNullaryOp<Eigen::ei_scalar_constant_op<double>, Eigen::Matrix<double, 6, 1, 2, 6, 1> > > (
    this=0x7f42db4, other=@0x7f42ccc) at /opt/qnx641/target/qnx6/mrlib/include/eigen2/Eigen/src/Core/Matrix.h:405
#7  0x080981a4 in A (this=0x7f42db4) at mrmath/ft_v_vector.cc:28
#8  0x0809820f in B (this=0x7f42db4) at mrmath/ft_v_vector.cc:185
#9  0x08078293 in mrrocpp::edp::common::manip_effector::compute_servo_joints_and_frame (this=0x80d7fc0) at edp_e_manip.cc:55

The code, that causes the abort is just creating local, temporary variable of class B:
B servo_real_kartez_pos;

I have checked, that QNX compiler honours EIGEN_ALIGN_128 statement (I am 100% sure,
checked with gdb for very simple structure alignment with and without this statement).

The question is - where is my mistake? Is it correct to make inherit in the above way?
The problem seems to be, that in frames #8 to #4 "this" is not aligned to 128bit boundary.
I have tried adding EIGEN_ALIGN_128 and virtual inheritance, but this did not solve the problem.

Thanks in advance!

Piotr Trojanek
Robot Control and Recognition Systems Team,
Institute of Control & Computation Engineering,
Warsaw University of Technology

Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/