0

Here's the code I'm using:

typedef boost::adjacency_list<boost::vecS, boost::vecS, boost::bidirectionalS>
Graph;

Graph g;
typedef graph_traits<Graph>::vertex_descriptor Vertex;
typedef graph_traits<Graph>::edge_descriptor Edge_Desc;
typedef graph_traits<Graph>::vertex_iterator vertex_iterator;

Vertex u, v;
u = boost::add_vertex(g);
v = boost::add_vertex(g);

Edge_Desc edge;
bool inserted = false;
boost::tie(edge,inserted) = boost::add_edge(u,v,g);

boost::remove_edge(edge,g);
cout<<"\nAfter removing edge"<<endl;

cout<<"\nRemove u"<<endl;
boost::remove_vertex(u,g);

cout<<"\nRemove v"<<endl;
boost::remove_vertex(v,g);
cout<<"\n!Everything removed"<<endl;

In the console I see upto "Remove v" and I get the *.exe has stopped working window. So removing the last vertex threw the exception.

When I catch the exception and print it, it says "bad allocation." In my actual program (above I have a simple test program) it says "Caught std::exception: vector too long. Looks like there was a divide by zero for the vector length. Any ideas why this is happening?

Update: I'm using MS VS2010 compiler with boost version 1.51

Dula
  • 1,404
  • 1
  • 14
  • 29
  • I might be wrong, but nothing changes [with the old C++ standard](http://coliru.stacked-crooked.com/a/c1f0bb3b15c267f0). What compiler are you using? (hint: Windows is not a compiler) Also no, there isn't "a lot of differences between your environment and mine" because any decent compiler would provide a standardized implementation for the standard library and `boost` is portable via the standard library. – Shoe May 29 '14 at 17:42
  • The Microsoft Visual Studio 2010 compiler. My boost version is 1.51. Latest is 1.55. Not sure if anything has changed since then. – Dula May 29 '14 at 17:45
  • @LightnessRacesinOrbit I dug a little deeper and found that this line is the one throwing the exception: g.m_vertices.erase(g.m_vertices.begin() + u); #1973 on adjacency_list.hpp – Dula May 29 '14 at 18:25
  • @Dula: `std::code_is_invisible_exception` – Lightness Races in Orbit May 29 '14 at 18:25
  • yeah I hit the 'enter' key by mistake. that line basically boils down to: vector a; a.push_back(5); a.erase(a.begin() + 1); // this line throws the same exception – Dula May 29 '14 at 18:27
  • so this is clearly not going to work because a.begin()+1 will go pass the boundary. – Dula May 29 '14 at 18:28
  • @dula You mean [this `adjacency_list.hpp`](http://www.boost.org/doc/libs/1_52_0/boost/graph/adjacency_list.hpp)? – Shoe May 29 '14 at 18:48
  • no this one [adjacency_list.hpp](http://www.boost.org/doc/libs/1_51_0/boost/graph/detail/adjacency_list.hpp) it's in boost/graph/detail. didn't catch that before – Dula May 29 '14 at 18:50

0 Answers0