任何 GraphAttributes 函数调用上的 OGDF 段错误

OGDF segfault on any GraphAttributes function call

本文关键字:错误 段错误 OGDF GraphAttributes 函数调用 任何      更新时间:2023-10-16
我刚刚开始使用 OGDF,

并尝试通过运行 OGDF 网页上 How-Tos 下的一些示例来掌握它。我的代码可以编译,但是当我尝试在节点上调用 GraphAttributes 函数时,它会出现段错误。

这是我的代码:

   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);
   }

如果我注释掉我在注释中提到的行会导致段错误,则程序在没有段错误的情况下运行良好。如果我然后查看写出的 .gml 文件,节点具有 x 和 y 坐标。我收到以下消息:

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.

当我在 GraphAttributes 上调用不同的函数时,也会发生这种情况,例如 .idNode(v(。

有人可以指出我正确的方向,为什么会发生这种情况吗?我现在绝对不明白这是从哪里来的,而 OGDF 只是遍历代码并理解它。(至少对我来说(

提前非常感谢!

不幸的是,你的问题不容易重现。

我的直觉是在从文件加载图形后初始化图形属性。

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 );

或者在加载图形后调用 initAttributes。

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);

希望这会有所帮助。

对我来说

没有 -DOGDF_DEBUG 的构建是可行的。

断言(意外失败(仅在调试模式下检查。

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