This forum has been archived. All content is frozen. Please use KDE Discuss instead.

Quaternion assignment crash problem?

Tags: None
(comma "," separated)
ffhighwind
Registered Member
Posts
2
Karma
0
My code seems to be crashing when I assign a Quaternion using the = operator. I've chopped out most of the useless bits... if anybody can help.

Code: Select all
#define EIGEN_NO_MALLOC 1
#define EIGEN_FAST_MATH 1
#include <Eigen/Dense>
typedef Eigen::Quaternionf Quaternion;
typedef Eigen::Vector3f vec3;

inline Quaternion makeQuat(const vec3 &vec)
{
   float w = 1.0f - (vec.x() * vec.x()) - (vec.y() * vec.y()) - (vec.z() * vec.z());
   return Quaternion(w < 0.0f ? 0.0f : -sqrt(w), vec.x(), vec.y(), vec.z());
}
//...
typedef struct joint_t
{
   vec3 pos;
   Quaternion orient;
} joint;
//...
vec3 orVec;
if (sscanf (buff, "( %f %f %f ) ( %f %f %f )",
   &ajoint->pos[0], &ajoint->pos[1], &ajoint->pos[2], &orVec[0], &orVec[1], &orVec[2]) == 8)
{
   Quaternion q = makeQuat(orVec);;
   joints[i].orient = q; // CRASH
}


Eigen::internal::pstore<float,__m128>(float * to, const __m128 & from) Line 292
Eigen::internal::pstoret<float,__m128,1>(float * to, const __m128 & from) Line 292
Eigen::PlainObjectBase<Eigen::Matrix<float,4,1,0,4,1> >::writePacket<1>(int row, int col, const __m128 & x) Line 185
Eigen::DenseCoeffsBase<Eigen::Matrix<float,4,1,0,4,1>,1>::copyPacket<Eigen::Matrix<float,4,1,0,4,1>,1,1>(int row, int col, const Eigen::DenseBase<Eigen::Matrix<float,4,1,0,4,1> > & other) Line 523
Eigen::DenseCoeffsBase<Eigen::Matrix<float,4,1,0,4,1>,1>::copyPacketByOuterInner<Eigen::Matrix<float,4,1,0,4,1>,1,1>(int outer, int inner, const Eigen::DenseBase<Eigen::Matrix<float,4,1,0,4,1> > & other) Line 549
Eigen::internal::assign_innervec_CompleteUnrolling<Eigen::Matrix<float,4,1,0,4,1>,Eigen::Matrix<float,4,1,0,4,1>,0,4>::run(Eigen::Matrix<float,4,1,0,4,1> & dst, const Eigen::Matrix<float,4,1,0,4,1> & src) Line 208
Eigen::internal::assign_impl<Eigen::Matrix<float,4,1,0,4,1>,Eigen::Matrix<float,4,1,0,4,1>,2,2,0>::run(Eigen::Matrix<float,4,1,0,4,1> & dst, const Eigen::Matrix<float,4,1,0,4,1> & src) Line 343
Eigen::DenseBase<Eigen::Matrix<float,4,1,0,4,1> >::lazyAssign<Eigen::Matrix<float,4,1,0,4,1> >(const Eigen::DenseBase<Eigen::Matrix<float,4,1,0,4,1> > & other) Line 500
Eigen::PlainObjectBase<Eigen::Matrix<float,4,1,0,4,1> >::lazyAssign<Eigen::Matrix<float,4,1,0,4,1> >(const Eigen::DenseBase<Eigen::Matrix<float,4,1,0,4,1> > & other) Line 394
Eigen::internal::assign_selector<Eigen::Matrix<float,4,1,0,4,1>,Eigen::Matrix<float,4,1,0,4,1>,0,0>::run(Eigen::Matrix<float,4,1,0,4,1> & dst, const Eigen::Matrix<float,4,1,0,4,1> & other) Line 522
Eigen::PlainObjectBase<Eigen::Matrix<float,4,1,0,4,1> >::_set_noalias<Eigen::Matrix<float,4,1,0,4,1> >(const Eigen::DenseBase<Eigen::Matrix<float,4,1,0,4,1> > & other) Line 600
Eigen::PlainObjectBase<Eigen::Matrix<float,4,1,0,4,1> >::_set_selector<Eigen::Matrix<float,4,1,0,4,1> >(const Eigen::Matrix<float,4,1,0,4,1> & other, const Eigen::internal::false_type & __formal) Line 585
Eigen::PlainObjectBase<Eigen::Matrix<float,4,1,0,4,1> >::_set<Eigen::Matrix<float,4,1,0,4,1> >(const Eigen::DenseBase<Eigen::Matrix<float,4,1,0,4,1> > & other) Line 578
Eigen::Matrix<float,4,1,0,4,1>::operator=(const Eigen::Matrix<float,4,1,0,4,1> & other) Line 157
Eigen::QuaternionBase<Eigen::Quaternion<float,0> >::operator=(const Eigen::QuaternionBase<Eigen::Quaternion<float,0> > & other) Line 482
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
It seems you are hitting an alignment issue. Just to be sure, could you try with the devel branch. If that still crash, could you detail your platform (system,CPU,compiler). It might be that on your platform the stack is not aligned. You can also compile with EIGEN_DONT_ALIGN_STATICALLY. For details you can read these pages:
http://eigen.tuxfamily.org/dox-devel/gr ... ement.html
ffhighwind
Registered Member
Posts
2
Karma
0
I see. According to the link I have use EIGEN_MAKE_ALIGNED_OPERATOR_NEW or typedef my Quaternion to the no_aligned version since I'm using a struct with an Eigen member. I also might have to include <Eigen/StdVector>.

Since you asked, I'm running under 64 bit Windows 7 Professional and compiling with Visual Studio 2012 Ultimate under WIN 32.
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
Right, I did not pay attention to that, but you have to add EIGEN_MAKE_ALIGNED_OPERATOR_NEW to your class joint and use an aligned_allocator if joints is a std::vector.

btw, in c++ class and struct are declared like this:

Code: Select all
struct joint
{
   vec3 pos;
   Quaternion orient;
};


Bookmarks



Who is online

Registered users: Bing [Bot], Google [Bot], Sogou [Bot]