OGDF segfault on any GraphAttributes function call

353 Views Asked by At

I am just starting with OGDF and try to get a hang of it by running some of the examples that are on the OGDF webpage under How-Tos. My Code compiles, but it segfaults when I try to call a GraphAttributes function on a node.

Here my Code:

   ogdf::Graph G;
   ogdf::GraphAttributes GA(G);

   if (!ogdf::GraphIO::readGML(G, "sierpinski_04.gml") ) {
      std::cerr << "Could not load sierpinski_04.gml" << std::endl;
      return 1;
   }


   ogdf::node v;

   GA.setAllHeight(10.0);
   GA.setAllWidth(10.0);

   ogdf::FMMMLayout fmmm;

   fmmm.useHighLevelOptions(true);
   fmmm.unitEdgeLength(15.0);
   fmmm.newInitialPlacement(true);
   //fmmm.qualityVersusSpeed(ogdf::FMMMLayout::qvsGorgeousAndEfficient);

   fmmm.call(GA);
   ogdf::GraphIO::writeGML(GA, "sierpinski_04-layout.gml");

   for(v=G.firstNode(); v; v=v->succ()) {
      std::cout << v << std::endl;
      //the following line causes the segfault
      double xCoord = GA.x(v);
   }

If I comment out the line that I mention in the comment is causing the segfault the program runs fine without a segfault. If I then look into the written out .gml file the nodes have x- and y- Coordinates. I am getting the following message:

MT: /home/work/lib/OGDF-snapshot/include/ogdf/basic/NodeArray.h:174: T& ogdf::NodeArray<T>::operator[](ogdf::node) [with T = double; ogdf::node = ogdf::NodeElement*]: Assertion `v->graphOf() == m_pGraph' failed.

It also happens when I call a different function on GraphAttributes, as for example .idNode(v).

Can someone point me in the right direction why this is happening? I do absolutly not understand where this is coming from by now, and OGDF is to big to just walk through the code and understand it. (At least for me)

Thank you very much in advance!

2

There are 2 best solutions below

3
Tezirg On

Unfortunatelly, your problem is not easy to reproduce.

My intuition would be to initialize the GraphAttributes after loading the Graph from the file.

ogdf::Graph G;
if (!ogdf::GraphIO::readGML(G, "sierpinski_04.gml") ) {
    std::cerr << "Could not load sierpinski_04.gml" << std::endl;
    return 1;
}
ogdf::GraphAttributes GA(G, ogdf::GraphAttributes::nodeGraphics |
                         ogdf::GraphAttributes::nodeStyle |
                         ogdf::GraphAttributes::edgeGraphics );

Or to call the initAttributes after loading the graph.

ogdf::Graph G;
ogdf::GraphAttributes GA(G);

if (!ogdf::GraphIO::readGML(G, "sierpinski_04.gml") ) {
   std::cerr << "Could not load sierpinski_04.gml" << std::endl;
   return 1;
}

GA.initAttributes(ogdf::GraphAttributes::nodeGraphics |
                  ogdf::GraphAttributes::nodeStyle |
                  ogdf::GraphAttributes::edgeGraphics);

Hopefully, that's helping.

0
JavAlex On

For me, building without -DOGDF_DEBUG worked.

The assertion (which accidentally fails) is only checked in debug mode.

In Graph_d.h:168:

#ifdef OGDF_DEBUG
    // we store the graph containing this node for debugging purposes
    const Graph *m_pGraph; //!< The graph containg this node (**debug only**).
#endif