3

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!

nurgan
  • 309
  • 1
  • 4
  • 22
  • You initialize `GA` with an empty graph `G`, see `ogdf::GraphAttributes GA(G);`. Do that initialization after the `... ogdf::GraphIO::readGML(G, "sierpinski_04.gml") ...`. – Andre Kampling May 24 '17 at 11:00

2 Answers2

1

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.

Tezirg
  • 1,629
  • 1
  • 10
  • 20
  • The initialization after loading the Graph does not change anything. The second one gives me the compiler error `error: ‘class ogdf::GraphAttributes’ has no member named ‘initAttributes’`. Also I forgot to take the attributes out of my code, the original example only has `ogdf::GraphAttributes GA(G);` which results in the exact same behavior, the additional attributes was just my own try to somehow fix it. – nurgan May 18 '17 at 10:17
  • I see, so it's not helping.. For the ` initAttributes` It should be there according to the documentation : http://www.ogdf.net/doc-ogdf/classogdf_1_1_graph_attributes.html#a9e4e13bc39e2d8a4ebe32c1b0a7ada05 Are you using a deprectad version maybe ? – Tezirg May 18 '17 at 12:13
  • I'm using the newest version. Can it be related to how i include the lib with cmake? I also had to change `forall_nodes(v,G)` which is definied in ogdf as a macro to `for(v=G.firstNode(); v; v=v->succ())` because it couldn't find the macro. I do absolutly not understand why this is happening. Also the line `//fmmm.qualityVersusSpeed(ogdf::FMMMLayout::qvsGorgeousAndEfficient);` is commented out, because it says qvsGorgeousAndEfficient is not a member of FMMMLayout, which it obviously is. Maybe that makes it more clear what happens? Not to me tho. – nurgan May 18 '17 at 12:36
0

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
JavAlex
  • 4,974
  • 1
  • 12
  • 14