【问题标题】:Removing vertex and adding it back again causes crash in boost::graph?删除顶点并再次添加它会导致 boost::graph 崩溃?
【发布时间】:2011-12-14 15:22:24
【问题描述】:

我正在使用带标签的图表

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 函数来删除/添加东西。

【问题讨论】:

  • @JeremiahWillcock 我已经用相关信息更新了问题。
  • 您是否尝试过 Valgrind 或调试器等工具来找出代码试图错误访问的内容?

标签: boost boost-graph


【解决方案1】:

崩溃是由boost::labeled_graph 的实现中的错误导致的。它出现在 Boost 1.54.0 和 1.55.0(最新版本)中。我通过 Boost 的 Trac reported it

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-10-22
    • 2016-01-25
    • 1970-01-01
    • 1970-01-01
    • 2013-05-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多