任何 GraphAttributes 函数调用上的 OGDF 段错误
OGDF segfault on any GraphAttributes function call
我刚刚开始使用 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
相关文章:
- 为什么PyImport_ImportModule python 3.7.2 中出现段错误?
- 为什么在访问 vtkRenderWindow 的"交互器"变量时会发生段错误?
- 全局向量导致 C++ 程序结束时出现段错误
- 为什么重载运算符<<打印特征类成员会导致段错误?
- 更改条件段错误
- 使用 TTF_RenderText() 加载字体时获取段错误 TTF_OpenFontRW()
- 注册对对象工厂的调用会导致段错误
- pthread_create在构造函数段错误中
- Nanoflann发现邻居提出段错误
- C++ 中的构造函数、继承、堆栈、堆、this-pointer 和段错误
- 具有unique_ptr的 CRTP 会导致段错误
- 增强纤维work_stealing屏障会导致段错误
- 当我返回指向结构的指针向量时出现段错误
- C++为什么我的代码没有爆炸/段错误?
- Pthread段错误,使用指向main中变量的指针
- C++ 模板中的段错误
- 相当于Windows/MSVC上的段错误?
- 为什么我的 LLVM JIT 实现出现段错误?
- 为什么访问我的引用捕获变量会导致我的 lambda 函数出现段错误?
- 为什么自删除的全局 Vulkan 实例仅在添加层时才导致段错误?