我正在使用带标签的图表
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)
在设置新添加顶点的字段时(上面注释为“这里崩溃”)。
可能是什么原因?我正在使用增强功能来删除/添加东西。