繁体   English   中英

琐碎的C ++向量中的神秘分割错误

[英]mysterious segmentation fault in trivial C++ vector

我想在这种方法中以某种迭代方式为向量p-> vertexlist赋值,并且当j = 3和i = 2时(在for迭代中)一直存在内存问题。

void py_tetgenio::set_facets(bp::list python_facets) {

this->numberoffacets = bp::len(python_facets);
this->facetlist = new tetgenio::facet[this->numberoffacets];
this->facetmarkerlist = new int[this->numberoffacets];

for (int i = 0; i < this->numberoffacets; i++) {
    //iterar por sobre la lista agregando cada uno de los
    //identificadores a cada uno de los facets
    bp::list facet = bp::extract<bp::list>(python_facets[i]);

    tetgenio::facet *f = &this->facetlist[i];
    f->numberofpolygons = 1;
    f->polygonlist = new tetgenio::polygon[f->numberofpolygons];
    f->numberofholes = 0;
    f->holelist = NULL;
    tetgenio::polygon *p = &f->polygonlist[i];

    //iterar por sobre la lista de los id de los nodos
    //almacenados en la lista que representa al facets

    p->numberofvertices = bp::len(facet);
    p->vertexlist = new int[p->numberofvertices];

    for (int j = 0; j < p->numberofvertices; j++) {
        int aux = bp::extract<int>(facet[j]);
        p->vertexlist[j] = aux; // SIGSEV:  Segmentation Fault!!! when j=3 
                                            // and i = 2
    }
    this->facetmarkerlist[i] = 1;
}
} //end set_facets

这是一个

注意:我们被告知i是2。

f->numberofpolygons = 1;
f->polygonlist = new tetgenio::polygon[f->numberofpolygons];

现在f->polygonlist指向大小为1的数组。

// Two irrelevant statements skipped
tetgenio::polygon *p = &f->polygonlist[i];

p现在是f->polygonlist中的第三个i == 2 )多边形的f->polygonlist 哦,但是

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM