我刚刚开始使用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);
}如果我注释掉我在注释中提到的那一行导致了segfault,那么程序就可以正常运行而不会出现Segfault值。如果我随后查看写出的.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太大了,以至于只需浏览代码并理解它。(至少对我来说)
非常感谢您的提前!
发布于 2017-05-18 17:43:49
不幸的是,您的问题不容易重现。
我的直觉是在从文件加载图形之后初始化GraphAttributes。
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);希望这会有帮助。
发布于 2019-06-14 23:42:55
对我来说,在没有-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**).
#endifhttps://stackoverflow.com/questions/43947474
复制相似问题