Fixed crash when removing vertex

This commit is contained in:
Anna Rose 2011-06-27 23:05:14 -04:00
parent 2bddf92001
commit a40773d8b0

View File

@ -114,7 +114,7 @@ bool Graph::add_vertex(int x, int y, int r, int colour, int score, Vertex* src)
vertices.push_back(v); vertices.push_back(v);
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr, "debug: Graph::add_vertex(): added: x=%d, y=%d, r=%d, score=%d\n", v->x, v->y, v->r, v->score); fprintf(stderr, "debug: Graph::add_vertex(): added: x=%d, y=%d, r=%d, score=%d, colour=%x\n", v->x, v->y, v->r, v->score, v->colour);
#endif #endif
return true; return true;
@ -143,11 +143,11 @@ void Graph::remove_vertex(Vertex* target)
for (cursor = target->neighbors.begin(); cursor != target->neighbors.end(); for (cursor = target->neighbors.begin(); cursor != target->neighbors.end();
cursor++) cursor++)
{ {
list<Vertex*>::iterator subcursor = find(target->neighbors.begin(), list<Vertex*>::iterator subcursor = find((*cursor)->neighbors.begin(),
target->neighbors.end(), (*cursor)->neighbors.end(),
*cursor); target);
assert(subcursor != target->neighbors.end()); assert(subcursor != (*cursor)->neighbors.end());
target->neighbors.erase(subcursor); (*cursor)->neighbors.erase(subcursor);
} }
cursor = find(vertices.begin(), vertices.end(), target); cursor = find(vertices.begin(), vertices.end(), target);