I am using the G+Smo library for some interpolation, and keep running in "double free or corruption" errors at runtime when using the library functions. Eventually, my goal is to wrap it in order to call this from much user-friendlier Python.
The minimal working example I have written is the following:
#include "gismo.h"
#include <vector>
using namespace std;
int main()
{
vector<real_t> pos_nodes;
real_t periode_x = 1.0;
index_t nb_nodes_x = 10;
for (int i = 0; i<nb_nodes_x; i++)
{
pos_nodes.push_back(periode_x/(nb_nodes_x+1) * i);
}
gismo::gsKnotVector<real_t> nodex(pos_nodes, 3);
// Create a node vector based on the positions given
cout << nodex;
gismo::gsTensorBSplineBasis<2, real_t> base(node_x, node_x);
// Create a Tensor BSpline Basis based on the node vectors
cout << base;
gismo::gsMatrix<real_t>; // Until there everything works
// base.anchors_into(res); // Uncomment any of those lines and runtime will crash
// res = base.anchors(); // Uncomment any of those lines and runtime will crash
return 0;
}
This code compiles, even with one of the last 2 lines uncommented, but gives errors at runtime.
The function anchors_into
is defined in gsTensorBasis.h as:
template<short_t d, class T>
void gsTensorBasis<d,T>::anchors_into(gsMatrix<T>& result) const
{
gsMatrix<T> gr[d];
gsVector<unsigned, d> v, size;
result.resize( d, this->size() );
for (short_t i = 0; i < d; ++i)
{
gr[i] = m_bases[i]->anchors();
size[i] = this->size(i);
}
// iterate over all tensor product basis functions
v.setZero();
unsigned r = 0;
do {
// Make tensor product of greville points
for (unsigned i=0; i<d; ++i )
result(i,r)= (gr[i])( 0, v(i) );
++r ;
} while (nextLexicographic(v, size));
}
I have tried defining the res
variable globally (it solved the problem at another place in my code, not here), or using the function anchor_into(10, res)
to find the anchor of the 10th base function, but when I execute, all options end up with:
...blabla printing the node vector...
...blabla printing the basis definition...
double free or corruption (out)
Aborted (core dumped)
I have no idea where to look for problems, if I misuse the library or if the library itself has a problem. I've gone through quite a few questions about similar errors on this website, but most were linked to personal class/struct definitions, which I do not do.