Fixed crash when removing vertex
This commit is contained in:
parent
2bddf92001
commit
a40773d8b0
12
graph.cpp
12
graph.cpp
|
@ -114,7 +114,7 @@ bool Graph::add_vertex(int x, int y, int r, int colour, int score, Vertex* src)
|
|||
vertices.push_back(v);
|
||||
|
||||
#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
|
||||
|
||||
return true;
|
||||
|
@ -143,11 +143,11 @@ void Graph::remove_vertex(Vertex* target)
|
|||
for (cursor = target->neighbors.begin(); cursor != target->neighbors.end();
|
||||
cursor++)
|
||||
{
|
||||
list<Vertex*>::iterator subcursor = find(target->neighbors.begin(),
|
||||
target->neighbors.end(),
|
||||
*cursor);
|
||||
assert(subcursor != target->neighbors.end());
|
||||
target->neighbors.erase(subcursor);
|
||||
list<Vertex*>::iterator subcursor = find((*cursor)->neighbors.begin(),
|
||||
(*cursor)->neighbors.end(),
|
||||
target);
|
||||
assert(subcursor != (*cursor)->neighbors.end());
|
||||
(*cursor)->neighbors.erase(subcursor);
|
||||
}
|
||||
|
||||
cursor = find(vertices.begin(), vertices.end(), target);
|
||||
|
|
Loading…
Reference in New Issue
Block a user