Fri Nov 09, 2012 10:12 pm
I am new to the Eigen library and have a question about a segmentation fault I am getting. I have a class method that does certain computations. When I run the code however, it crashes with a segmentation fault. The method called is
void CrossTrack::iterateCrossTrack(const VectorXd& x, Vector3d& vr, Vector3d& omga, Vector3d& mxtrac)
and takes x as input and updates vr, omega and mxtrac after doing certain computations. The segmentation fault occurs at the very end of the method.
//-- METHOD BODY
vr = VR;
omga = omega;
mxtrac = M_CrossTrack; // THIS IS WHERE SEGFAULT OCCURS
} // END OF METHOD
If I comment out the last line (// mxtrac = M_CrossTrack), then the segfault occurs at (omga = omega). This segfault seems to be related to alignment but I am not very knowledgeable about that aspect of Eigen. As per documentation, I have added
to the class since it contains fixed size vectors and matrices.
The relavent part of the gdb trace is as follows:
#0 0xb615ecf6 in free () from /lib/libc.so.6
#1 0xb6a3fbd7 in handmade_aligned_free (ptr=<optimized out>) at /usr/include/eigen3/Eigen/src/Core/util/Memory.h:116
#2 aligned_free (ptr=<optimized out>) at /usr/include/eigen3/Eigen/src/Core/util/Memory.h:246
#3 conditional_aligned_free<true> (ptr=<optimized out>) at /usr/include/eigen3/Eigen/src/Core/util/Memory.h:312
#4 conditional_aligned_delete_auto<double, true> (ptr=<optimized out>, size=<optimized out>)
#5 ~DenseStorage (this=<optimized out>, __in_chrg=<optimized out>)
#6 ~PlainObjectBase (this=<optimized out>, __in_chrg=<optimized out>)
#7 ~Matrix (this=<optimized out>, __in_chrg=<optimized out>) at /usr/include/eigen3/Eigen/src/Core/Matrix.h:140
#8 auv::controller::CrossTrack::iterateCrossTrack (this=0x895fe660, x=..., vr=..., omga=..., mxtrac=...)
#9 0xb6a40a8f in auv::controller::CrossTrack::iterate (this=0x810a700)
I will certainly appreciate any input in this regard.
Sat Nov 10, 2012 3:08 am
An update on this segmentation fault. I forgot to mention that I was using RelWithDebInfo build from CMake, which basically has "-g -O2" flags. This segmentation fault does not occur if instead I use "Debug" build, with "-g -O0" option. I am wondering if the optimization is causing any weird behavior.
Sat Nov 10, 2012 1:38 pm
it's impossible to help you without the full function code.
Sat Nov 10, 2012 2:47 pm
Without knowing anything about this case in specific, getting crashes depending on what compiler flags are being used sounds like subtle memory management errors or similar in your code. Try running it trough valgrind and fix anything it tells you, that'll probably help.
I'm working on python language support for KDevelop.