[BGL] Segfaults when switching from digraph to undirected graph

Hi, I ran into trouble after changing my directed adjacency_list into an undirected graph. The following code causes a segfault: for (set<Node>::iterator n = nodes.begin(); n != nodes.end(); ++n) { graph_traits<Graph>::out_edge_iterator edges_begin, edges_end; tie(edges_begin, edges_end) = out_edges(*n, g); for (graph_traits<Graph>::out_edge_iterator ne = edges_begin; ne != edges_end; ++ne) { Node nn1 = target(*ne, g); // ... K_o = out_degree(nn1, g); graph_traits<Graph>::out_edge_iterator nn1edges_begin, nn1edges_end; tie(nn1edges_begin, nn1edges_end) = out_edges(nn1, g); int k; graph_traits<Graph>::out_edge_iterator nn1e; for (nn1e = nn1edges_begin; nn1e != nn1edges_end; ++nn1e) { k = 0; if (nodes.count(target(*nn1e, g))) // !!! k++; } } } I cut out most of the stuff not directly related to accessing the graph. It segfaults in the line marked by !!!, so it would seem that out_edges returns an invalid range (I did some debugging and the this line executes quite a few times before the iterator becomes invalid. I can't seem to force gdb to recognise nn1e as a symbol so I can't tell which edge/node is causing the problem. All this is ran after the graph is initialised (it's quite large, ab. 22k nodes and 900k edges). Best regards, Greg

I cut out most of the stuff not directly related to accessing the graph. It segfaults in the line marked by !!!, so it would seem that out_edges returns an invalid range (I did some debugging and the this line executes quite a few times before the iterator becomes invalid. I can't seem to force gdb to recognise nn1e as a symbol so I can't tell which edge/node is causing the problem. All this is ran after the graph is initialised (it's quite large, ab. 22k nodes and 900k edges).
You should include the definition of the graph's type. There are some subtle tradeoffs when selecting vecS vs. listS, etc. Are you modifying the graph in any way in the code that you're omitting? Andrew Sutton andrew.n.sutton@gmail.com

On 28 Jan 2009, at 13:56, Andrew Sutton wrote:
I cut out most of the stuff not directly related to accessing the graph. It segfaults in the line marked by !!!, so it would seem that out_edges returns an invalid range (I did some debugging and the this line executes quite a few times before the iterator becomes invalid. I can't seem to force gdb to recognise nn1e as a symbol so I can't tell which edge/node is causing the problem. All this is ran after the graph is initialised (it's quite large, ab. 22k nodes and 900k edges).
You should include the definition of the graph's type. There are some subtle tradeoffs when selecting vecS vs. listS, etc.
Please disregard my previous message. Debugger sent me on a wild goose chase, the problem was in fact with property maps. Sorry about that. Regards, Greg
participants (2)
-
Andrew Sutton
-
Grzegorz Slodkowicz