From 411b4a1b1d054d1b7404e66288ac0fe92ed58d7e Mon Sep 17 00:00:00 2001 From: Benoit Jacob Date: Mon, 31 Oct 2011 09:23:41 -0400 Subject: [PATCH] bug #369 - Quaternion alignment is broken The problem was two-fold: * missing aligned operator new * Flags were mis-computed, the Aligned constant was misused --- Eigen/src/Geometry/Quaternion.h | 13 +++++++++---- test/geo_quaternion.cpp | 5 ++++- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/Eigen/src/Geometry/Quaternion.h b/Eigen/src/Geometry/Quaternion.h index 2662d60fe..7d6be0799 100644 --- a/Eigen/src/Geometry/Quaternion.h +++ b/Eigen/src/Geometry/Quaternion.h @@ -185,7 +185,7 @@ public: return typename internal::cast_return_type >::type( coeffs().template cast()); } - + #ifdef EIGEN_QUATERNIONBASE_PLUGIN # include EIGEN_QUATERNIONBASE_PLUGIN #endif @@ -225,22 +225,25 @@ struct traits > typedef _Scalar Scalar; typedef Matrix<_Scalar,4,1,_Options> Coefficients; enum{ - IsAligned = bool(EIGEN_ALIGN) && ((int(_Options)&Aligned)==Aligned), + IsAligned = internal::traits::Flags & AlignedBit, Flags = IsAligned ? (AlignedBit | LvalueBit) : LvalueBit }; }; } template -class Quaternion : public QuaternionBase >{ +class Quaternion : public QuaternionBase > +{ typedef QuaternionBase > Base; + enum { IsAligned = internal::traits::IsAligned }; + public: typedef _Scalar Scalar; EIGEN_INHERIT_ASSIGNMENT_EQUAL_OPERATOR(Quaternion) using Base::operator*=; - typedef typename internal::traits >::Coefficients Coefficients; + typedef typename internal::traits::Coefficients Coefficients; typedef typename Base::AngleAxisType AngleAxisType; /** Default constructor leaving the quaternion uninitialized. */ @@ -274,6 +277,8 @@ public: inline Coefficients& coeffs() { return m_coeffs;} inline const Coefficients& coeffs() const { return m_coeffs;} + EIGEN_MAKE_ALIGNED_OPERATOR_NEW_IF(IsAligned) + protected: Coefficients m_coeffs; diff --git a/test/geo_quaternion.cpp b/test/geo_quaternion.cpp index e03245654..1e7b2cba0 100644 --- a/test/geo_quaternion.cpp +++ b/test/geo_quaternion.cpp @@ -120,6 +120,10 @@ template void quaternion(void) VERIFY_IS_APPROX(q1f.template cast(),q1); Quaternion q1d = q1.template cast(); VERIFY_IS_APPROX(q1d.template cast(),q1); + + // test bug 369 - improper alignment. + Quaternionx *q = new Quaternionx; + delete q; } template void mapQuaternion(void){ @@ -191,7 +195,6 @@ template void check_const_correctness(const PlainObjec VERIFY( !(Map::Flags & LvalueBit) ); } - void test_geo_quaternion() { for(int i = 0; i < g_repeat; i++) {