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

Crash on destruction of std::vector with Eigen members

Tags: None
(comma "," separated)
stefanTUD
Registered Member
Posts
5
Karma
0
Hi everyone,
I currently get a crash when using a std::vector of classes containing Eigen members. I thought I already do everything that is recommended (use #include<Eigen/StdVector> and custom allocator), but the crash on destruction of said vector still happens.
I'm on a 64bit Natty system using gcc 4.5.2 and using the Eigen3 version currently available as a ROS package (there's a file eigen-3.0prebeta3.tar.bz2.md5sum packed with that, I assume that's the Eigen version).

Thanks to everyone looking at the problem.

The backtrace is (as mentioned before, the SIGABRT happens on destruction of the std::vector of JointKalmanFilter<double> objects):
Code: Select all
Program received signal SIGABRT, Aborted.
0x00007ffff5498d05 in raise (sig=6)
    at ../nptl/sysdeps/unix/sysv/linux/raise.c:64
64   ../nptl/sysdeps/unix/sysv/linux/raise.c: No such file or directory.
   in ../nptl/sysdeps/unix/sysv/linux/raise.c
(gdb) bt
#0  0x00007ffff5498d05 in raise (sig=6)
    at ../nptl/sysdeps/unix/sysv/linux/raise.c:64
#1  0x00007ffff549cab6 in abort () at abort.c:92
#2  0x00007ffff54d1d7b in __libc_message (do_abort=2,
    fmt=0x7ffff55ba400 "*** glibc detected *** %s: %s: 0x%s ***\n")
    at ../sysdeps/unix/sysv/linux/libc_fatal.c:189
#3  0x00007ffff54dda8f in malloc_printerr (av=<value optimized out>,
    p=0x6457c0) at malloc.c:6283
#4  _int_free (av=<value optimized out>, p=0x6457c0) at malloc.c:4795
#5  0x00007ffff54e18e3 in __libc_free (mem=<value optimized out>)
    at malloc.c:3738
#6  0x000000000041aef8 in Eigen::internal::conditional_aligned_free<false> (
    ptr=0x6457d0)
    at /opt/ros/diamondback/stacks/geometry/eigen/include/Eigen/src/Core/util/Memory.h:290
#7  0x000000000041b766 in Eigen::Matrix<double, 3, 3, 0, 3, 3>::operator delete
    (ptr=0x6457d0)
    at /opt/ros/diamondback/stacks/geometry/eigen/include/Eigen/src/Core/Matrix.h:154
#8  0x000000000041b329 in JointKalmanFilter<double>::~JointKalmanFilter (
    this=0x645680, __in_chrg=<value optimized out>)
---Type <return> to continue, or q <return> to quit---
    at /home/stefan/rosext/sk_sandbox/joint_kalman_test/src/JointKalmanFilter.hpp:33
#9  0x000000000041cb01 in Eigen::aligned_allocator<JointKalmanFilter<double> >::destroy (this=0x7fffffffdcf0, p=0x645680)
    at /opt/ros/diamondback/stacks/geometry/eigen/include/Eigen/src/Core/util/Memory.h:611
#10 0x000000000041be9f in std::_Destroy<JointKalmanFilter<double>*, Eigen::aligned_allocator_indirection<JointKalmanFilter<double> > > (__first=0x645680,
    __last=0x645780, __alloc=...)
    at /usr/include/c++/4.5/bits/stl_construct.h:140
#11 0x000000000041b4d4 in std::vector<JointKalmanFilter<double>, Eigen::aligned_allocator_indirection<JointKalmanFilter<double> > >::~vector (
    this=0x7fffffffdcf0, __in_chrg=<value optimized out>)
    at /usr/include/c++/4.5/bits/stl_vector.h:313
#12 0x000000000041b0f8 in std::vector<JointKalmanFilter<double>, Eigen::aligned_allocator<JointKalmanFilter<double> > >::~vector (this=0x7fffffffdcf0,
    __in_chrg=<value optimized out>)
    at /usr/include/c++/4.5/bits/stl_vector.h:171
#13 0x000000000041ac82 in main (argc=1, argv=0x7fffffffde38)
    at /home/stefan/rosext/sk_sandbox/joint_kalman_test/src/test.cpp:24


For this small testing code snippet:
Code: Select all
#include<Eigen/StdVector>
#include "JointKalmanFilter.hpp"

#include <vector>

using namespace std;


int main(int argc, char** argv)
{
  //single object works
  double time_diff = 1/1000.0;
  JointKalmanFilter<double> tmp;

  for (int i = 0; i < 100; ++i){
    tmp.update(time_diff,1.1);
    double pos = tmp.getPositionEstimate();
    double vel = tmp.getVelocityEstimate();
    std::cout << pos << " " << vel << "\n";
  }

  //vector of objects crashes on destruction
  std::vector<JointKalmanFilter<double>, Eigen::aligned_allocator<JointKalmanFilter<double> > > tmp_vec;
  tmp_vec.resize(4);

  for (int i = 0; i < 100; ++i){
    tmp_vec[1].update(time_diff,1.1);
    double pos = tmp_vec[1].getPositionEstimate();
    double vel = tmp_vec[1].getVelocityEstimate();
    std::cout << pos << " " << vel << "\n";
  }
  std::cout << "\nEND\n";

  return 0;
}


Relevant parts of JointKalmanFilter:
Code: Select all
#include <Eigen/Core>

template<typename ConcreteScalar>
class JointKalmanFilter{

public:

  EIGEN_MAKE_ALIGNED_OPERATOR_NEW;

  JointKalmanFilter()
  {
    state_mean_ = new Eigen::Matrix<ConcreteScalar, 3, 1>(Eigen::Matrix<ConcreteScalar, 3, 1>::Zero());
    state_cov_ = new Eigen::Matrix<ConcreteScalar, 3, 3>(Eigen::Matrix<ConcreteScalar, 3, 3>::Zero());

    process_model_A_ = new Eigen::Matrix<ConcreteScalar, 3, 3>(Eigen::Matrix<ConcreteScalar, 3, 3>::Zero());
    process_cov_Q_ = new Eigen::Matrix<ConcreteScalar, 3, 3>(Eigen::Matrix<ConcreteScalar, 3, 3>::Zero());

    observation_gain_K_ = new Eigen::Matrix<ConcreteScalar, 3, 1>(Eigen::Matrix<ConcreteScalar, 3, 1>::Zero());
    observation_update_tmp_ = new Eigen::Matrix<ConcreteScalar, 3, 3>(Eigen::Matrix<ConcreteScalar, 3, 3>::Zero());

    init();
  }

  virtual ~JointKalmanFilter()
  {
    delete state_mean_;
    delete state_cov_;

    delete process_model_A_;
    delete process_cov_Q_;

    delete observation_gain_K_;
    delete observation_update_tmp_;
  }

  //Member variables
  Eigen::Matrix<ConcreteScalar, 3, 1>* state_mean_;
  Eigen::Matrix<ConcreteScalar, 3, 3>* state_cov_;

  Eigen::Matrix<ConcreteScalar, 3, 3>* process_model_A_;
  Eigen::Matrix<ConcreteScalar, 3, 3>* process_cov_Q_;

  Eigen::Matrix<ConcreteScalar, 3, 1>* observation_gain_K_;
  Eigen::Matrix<ConcreteScalar, 3, 3>* observation_update_tmp_;
  ConcreteScalar observation_cov_R_;
};
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
It seems you are using a beta version, could you try with the latest stable release:

http://eigen.tuxfamily.org/index.php?ti ... e#Download


Bookmarks



Who is online

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