c++ - Segmentation fault raised from stl_list.h : 731 -


i've got weird segmentation fault code. actually, when run executable, aborts. when run gdb, aborts. when run valgrind, terminates , gives me correct result.

that's introduction. here's description of algorithm. want extracting subsurface of mesh looks similar one, given threshold, r. key idea of algorithm looping on each point of mesh (let's say, p). if find point of reference mesh included in sphere of center p , radius r, don't , go next point. otherwise, delete point , every element of mesh including (which means, edges, , triangles of mesh point belongs).

now jump short description of classes. have 4 classes represent elements of mesh :

  • vertex. class includes 2 attributes (i don't mention getters , setters) : position , list, belongsto, contains pointers of edges vertex belongs.
  • edge. class includes 3 attributes : 2 vertices delimiting edge, , list, called belongsto, wichi contains pointers of triangles edge belongs.
  • triangle. class includes 3 attributes : 3 edges delimiting triangle, , normal vector (i mentioned it, doesn't matter here : use render triangle using opengl).

and, :

  • mesh. class includes vector v of vertex objets, vector e of edge objects , vector t of triangles.

now here prototype of function :

class mesh {      ...      void extractidenticalsubsurfaces(mesh *a, double threshold);  } 

as may have guessed, function takes 2 parameters account : reference mesh , threshold (actually radius of sphere build determine if have delete point mesh). clear ?

description of algorithm : loop on each point of mesh (on each point of v, actually). each point, build sphere of radius 'threshold' centered in point , verify there point of in sphere. if find point, don't anything. otherwise, delete v.

but before doing that, have operations do.

indeed, have loop on each edge point belongs (using list 'belongsto') , on each triangle point belongs (once again using list 'belongsto').

for each of these triangles, loop on 3 edges delimiting , delete address of triangle list of edges triangle belongs (because want delete triangle, have anticipate).

once it's done, same current edge of loop : delete adress of edge 'belongsto' list associated 2 vertices of edge.

but have delete both suppressed edges , triangles vectors e , t !

it may seem not easy understand (i think it's better if have sheet of paper in front of , if draw mesh , consider point want suppress) quite sure of exactitude of algorithm : actually, when run program valgrind, displays sub-mesh on screen.

but problem if don't use valgrind, fails.

here's error message displayed gdb :

program received signal sigsegv, segmentation fault. 0x0000000000406f3a in std::list<triangle*, std::allocator<triangle*> >::begin (this=0x39) @ /usr/include/c++/4.6/bits/stl_list.h:731 731       { return iterator(this->_m_impl._m_node._m_next); } 

the backtrace :

(gdb) bt #0  0x0000000000406f3a in std::list<triangle*, std::allocator<triangle*> >::begin (this=0x39) @ /usr/include/c++/4.6/bits/stl_list.h:731 #1  0x0000000000406e37 in std::list<triangle*, std::allocator<triangle*> >::remove (this=0x39, __value=@0x7fffffffc860) @ /usr/include/c++/4.6/bits/list.tcc:242 #2  0x00000000004062a1 in edge::deletetriangle (this=0x21, t=0xcf4ed0) @ elements.cpp:109 #3  0x0000000000408aa4 in mesh::extractidenticalsubsurfaces (this=0xc14b10, a=0xc0f900, threshold=0) @ mesh.cpp:174 #4  0x0000000000404687 in scene::extractidenticalsurfaces (this=0xbad8c0, threshold=0) @ scene.cpp:36 #5  0x00000000004051c6 in viewer::keypressevent (this=0x7fffffffde80, e=0x7fffffffd020) @ viewer.cpp:104 ... 

as can see, getting error logical here, because system seems try apply 'deletetriangle' method on object 'this' address 0x21. wondering is, how on earth can 0x21. tried dislay adresses of pointers edges , vertices included in of triangles , edges objects, , seems correct (after can display of elements of mesh using opengl, so...). @ moment 0x21 comes in , don't know why.

this code :

void mesh::extractidenticalsubsurfaces (mesh *a, double threshold) {   vector<vertex *>::iterator it1 = v.begin() ;   while (it1 != v.end()) {     if (a->emptysphere((*it1), threshold)) {       list<edge *> edgestodelete = list<edge *>();       list<triangle *> trianglestodelete = list<triangle *>();       (list<edge *>::iterator it2 = (*it1)->getiteratorbegin() ; it2 != (*it1)->getiteratorend() ; it2++) {         (list<triangle *>::iterator it3 = (*it2)->getiteratorbegin() ; it3 != (*it2)->getiteratorend() ; it3++) {           triangle *argt = (*it3);           (*it3)->getfirstedge()->deletetriangle(argt);           (*it3)->getsecondedge()->deletetriangle(argt);           (*it3)->getthirdedge()->deletetriangle(argt);           trianglestodelete.push_back(argt);         }         edge *arge = (*it2);         (*it2)->getfirstvertex()->deleteedge(arge);         (*it2)->getsecondvertex()->deleteedge(arge);         edgestodelete.push_back(arge);       }       edgestodelete.unique();       trianglestodelete.unique();       vector<edge *>::iterator it4 = e.begin();       while (it4 != e.end()) {         bool isequal = false;         (list<edge *>::iterator it5 = edgestodelete.begin() ; it5 != edgestodelete.end() ; it5++) {           if ((*it4) == (*it5)) {             isequal = true;             edgestodelete.erase(it5);             break;           }         }         if (isequal) {           e.erase(it4);         } else {           it4++;         }       }       vector<triangle *>::iterator it6 = t.begin();       while (it6 != t.end()) {         bool isequal = false;         (list<triangle *>::iterator it7 = trianglestodelete.begin() ; it7 != trianglestodelete.end() ; it7++) {           if ((*it6) == (*it7)) {             isequal = true;             trianglestodelete.erase(it7);             break;           }         }         if (isequal) {           t.erase(it6);         } else {           it6++;         }          }       v.erase(it1);     } else {       it1++;     }   } } 

(well, not pretty sometimes, agree isn't subject of question (on first sight))

so, have idea of why error ?


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -