Boost logo

Boost Users :

Subject: [Boost-users] [BGL] Segfaults when switching from digraph to undirected graph
From: Grzegorz Slodkowicz (jergosh_at_[hidden])
Date: 2009-01-28 04:20:10


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


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net