0

我正在使用带标签的图表

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)

在设置新添加顶点的字段时(上面注释为“这里崩溃”)。

可能是什么原因?我正在使用增强功能来删除/添加东西。

4

1 回答 1

2

崩溃是由于boost::labeled_graph. 它出现在 Boost 1.54.0 和 1.55.0(最新版本)中。我通过 Boost 的 Trac报告了它。

我设法编写了一个简单的测试用例来揭示问题。运行它valgrind证明问题存在。我还创建了一个简单的补丁来解决我的设置问题boost::adjacency_list(请参阅所有这些文件的错误报告)。

于 2013-12-13T12:58:25.840 回答