删除顶点并再次添加回来会导致 boost::graph 崩溃吗?
我正在使用一个带标签的图
typedef boost::labeled_graph<boost::adjacency_list<boost::listS, boost::listS, boost::undirectedS, Room, RoomEdge>,std::string> MyGraph;
,它
struct LineSegment{
LineSegment(){portalToRoom="";}
LineSegment(QPointF startPos_, QPointF endPos_): startPos(startPos_), endPos(endPos_) { portalToRoom="";}
QPointF startPos;
QPointF endPos;
QGraphicsLineItem* sceneItem;
std::string type;
std::string portalToRoom;
};
struct Room{
Room(){centroid.setX(-1); centroid.setY(-1);}
std::string category;
std::string vertex_id;
std::vector<LineSegment> roomLayout;
QPointF centroid;
QGraphicsRectItem* centroidSceneItem;
};
struct RoomEdge{
std::string edge_id;
};
可以让我通过字符串 id 访问顶点。
我添加一个顶点并以这种方式设置它的相关字段:
MyVertex u = boost::add_vertex(id, g);
g[id].category = category; //crashes here
g[id].vertex_id = id;
并像这样删除它们:
// First we remove all edges from this vertex
BGL_FORALL_VERTICES(v, g, MyGraph){
if (QString(g.graph()[v].vertex_id.c_str()).compare(roomIdToBeRemoved) == 0){
ve = v;
BGL_FORALL_OUTEDGES(v, e, g, MyGraph) {
ev.push_back(e);
}
}
}
foreach(MyEdge e, ev){
remove_edge(e,g);
}
// Then we remove the vertex itself
remove_vertex(roomIdToBeRemoved.toStdString().c_str(),g);
到目前为止这似乎有效。问题是,如果我想使用相同的 id 再次添加已删除的顶点,我会得到以下信息:
Exception Type: EXC_BAD_ACCESS (SIGSEGV)
在设置新添加的顶点的字段时(上面注释为“此处崩溃”)。
可能是什么原因?我正在使用 boost 函数来删除/添加东西。
I'm using a labeled graph
typedef boost::labeled_graph<boost::adjacency_list<boost::listS, boost::listS, boost::undirectedS, Room, RoomEdge>,std::string> MyGraph;
with
struct LineSegment{
LineSegment(){portalToRoom="";}
LineSegment(QPointF startPos_, QPointF endPos_): startPos(startPos_), endPos(endPos_) { portalToRoom="";}
QPointF startPos;
QPointF endPos;
QGraphicsLineItem* sceneItem;
std::string type;
std::string portalToRoom;
};
struct Room{
Room(){centroid.setX(-1); centroid.setY(-1);}
std::string category;
std::string vertex_id;
std::vector<LineSegment> roomLayout;
QPointF centroid;
QGraphicsRectItem* centroidSceneItem;
};
struct RoomEdge{
std::string edge_id;
};
which lets me access vertices with string ids.
I add a vertex and set it's relevant fields this way:
MyVertex u = boost::add_vertex(id, g);
g[id].category = category; //crashes here
g[id].vertex_id = id;
And remove them like so:
// First we remove all edges from this vertex
BGL_FORALL_VERTICES(v, g, MyGraph){
if (QString(g.graph()[v].vertex_id.c_str()).compare(roomIdToBeRemoved) == 0){
ve = v;
BGL_FORALL_OUTEDGES(v, e, g, MyGraph) {
ev.push_back(e);
}
}
}
foreach(MyEdge e, ev){
remove_edge(e,g);
}
// Then we remove the vertex itself
remove_vertex(roomIdToBeRemoved.toStdString().c_str(),g);
This so far seems to work. The trouble is, if I want to add a removed vertex once again with the same id, I get the following:
Exception Type: EXC_BAD_ACCESS (SIGSEGV)
while setting the fields of the newly added vertex (above commented "crashes here").
What might be the reason? I'm using boost functions for removing/adding things.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
崩溃是由于
boost::labeled_graph
实现中的错误造成的。它出现在 Boost 1.54.0 和 1.55.0(最新版本)中。我通过 Boost 的 Trac 报告了。我设法编写了一个简单的测试用例来揭示问题。通过 valgrind 运行它证明问题存在。我还创建了一个简单的补丁来修复
boost::adjacency_list
设置的问题(请参阅所有这些文件的错误报告)。The crash is a result of a bug in the implementation of
boost::labeled_graph
. It's present both in Boost 1.54.0 and 1.55.0 (latest release). I reported it via Boost's Trac.I managed to write a simple test case that reveals the problem. Running it through
valgrind
proves that the issue exists. I also created a simple patch that fixes the problem for my setting ofboost::adjacency_list
(see the bug report for all these files).