Search code examples
runtime-erroralignmentruntimeheap-memoryeigen

Sometimes fails to create heap object (Eigen with custom structure)


I'm using a project which uses the Eigen library. I've had to already fixed an issue where when using the data types provided by eigen within a STL, I get an align error

error C2719: '_Val': formal parameter with __declspec(align('16')) won't be aligned

see

Once this was fixed i could compile and run.

But now at run time I'm getting another error

Debug Error!

R6010

abort() has been called.

So the code in question references my structure and a vector of my structure (with the eigen specially aligned fix):

typedef struct {
    Vector4f v4;
    Matrix4f M4;
    bool b;
} my_struct;

typedef std::vector<my_struct, Eigen::aligned_allocator<my_struct>> my_struct;

Then my code fails after a when I try to create a new my_struct after a certain number of iterations (it can sometimes creates the new object, with no problems), other times it fails.

for (int i = 0; i<len; i++) {
    Vector4f vec;
    Matrix4f mat;

     my_struct* temp = new my_struct();

}

Any ideas? Tom


Solution

  • Without -DNDEBUG, you should have got an assert sending you to this page. In your case, you should follow this one. In short, add EIGEN_MAKE_ALIGNED_OPERATOR_NEW to your structure such that new my_struct call an aligned memory allocator.