2013-12-21 50 views
0

欲分配值在某些迭代该方法的矢量对 - > VertexList时,并一直存储问题当j = 3和= 2(在为迭代)神秘段故障++矢量

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 

这是一个Mysterious

+3

请构建一个[最小测试用例](http://sscce.org)。 –

+0

我可以在这里放置一个eclipse调试器图像 – ljofre

+0

那么,p-> numberofverticies的价值是什么?在这种情况下, – OldProgrammer

回答

1

注:我们被告知i为2

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

现在f->polygonlist点大小为0的数组。

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

p现已在f->polygonlist第三i == 2)多边形的地址。哦,但是f->polygonlist指向一个大小为1的数组。

+0

卖你我的眼睛! – ljofre