2013-12-21 2 views
0

좀 반복이 방법에서 값에게 벡터 P-> 그러나 VertexList 할당하고 싶은 메모리 문제이었다 때 J = 3, I = 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

여기에 이클립스 디버거 이미지를 넣을 수 있습니다. – ljofre

+0

음, p-> numberofverticies의 값은 무엇입니까? 이 경우 – OldProgrammer

답변

1

주 : 우리는 i 크기 0의 배열 2.

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

이제 f->polygonlist 점이다 듣는다.

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

p 해주기 f->polygonlist (i == 2) 다각형의 주소이다. 오,하지만 f->polygonlist은 크기가 1 인 배열을 가리 킵니다.

+0

눈을 팔아주세요! – ljofre