samedi 6 mai 2023

Memory error when assigning Eigen objects to C array in loop

I have followed this advice here like so:

 ArrayXd simple_constraint = ArrayXd::Ones(10);
 double *b = simple_constraint.data();

Then b gets passed to a C api (CGAL, incidentally). However, this operation is repeated and takes place inside a loop, so that my code actually looks like this:

 for(int i=0;i<10;i++){
 \\do something 
     ArrayXd simple_constraint = someotherobject(i);
     double *b = simple_constraint.data();
}

After one iteration, i.e. when the assignment to the C arrays happens for the second time, I receive this error:

Process finished with exit code 136 (interrupted by signal 8: SIGFPE)

Can someone help me find out what I am doing wrong? Do I need to reallocate memory, free memory etc.? I tend to rely on C++ to do my memory management but was forced to pass pointers by the otherwise wonderful CGAL API.

Thank you!

Aucun commentaire:

Enregistrer un commentaire