0

我正在使用 G+Smo 库进行一些插值,并在使用库函数时在运行时继续运行“双重释放或损坏”错误。最终,我的目标是包装它,以便从用户友好的 Python 中调用它。

我编写的最小工作示例如下:

#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;
}

此代码编译,即使最后 2 行之一未注释,但在运行时给出错误。该函数anchors_into在 gsTensorBasis.h 中定义为:

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));
}

我已经尝试res全局定义变量(它在我的代码中的另一个地方解决了问题,而不是在这里),或者使用该函数anchor_into(10, res)来查找第 10 个基本函数的锚点,但是当我执行时,所有选项都以:

...blabla printing the node vector...
...blabla printing the basis definition...
double free or corruption (out)
Aborted (core dumped)

如果我滥用图书馆或图书馆本身有问题,我不知道在哪里寻找问题。我在这个网站上遇到了很多关于类似错误的问题,但大多数都与个人类/结构定义有关,我不这样做。

4

0 回答 0