【问题标题】:C++/STL Graphviz and Boost - Seg Fault ProblemC++/STL Graphviz 和 Boost - 段错误问题
【发布时间】:2010-09-05 02:15:50
【问题描述】:

我正在使用点语言通过 Boost 创建图表。我的图表很大,我正在尝试删除不再使用的图表。

在 boost/graph/graphviz.hpp 下 我添加了一个删除顶点的函数:

    virtual void
  do_remove_vertex( const node_t& node)
  {
    bgl_vertex_t v = bgl_nodes[node];
    clear_vertex(v,graph_);
    remove_vertex(v,graph_);
  }

但是我在清除顶点的调用中不断收到段错误,我将它运行到 gdb 中,这是回溯(我希望这不会太长)

Program received signal SIGSEGV, Segmentation fault.
0x000000000040b87f in std::_List_base<boost::detail::sep_<void*, boost::property<boost::edge_weight_t, int, boost::no_property> >, std::allocator<boost::detail::sep_<void*, boost::property<boost::edge_weight_t, int, boost::no_property> > > >::_M_clear (this=0x0) at /usr/include/c++/4.4/bits/list.tcc:68
68       _Node* __cur = static_cast<_Node*>(this->_M_impl._M_node._M_next);
(gdb) bt
#0  0x000000000040b87f in std::_List_base<boost::detail::sep_<void*, boost::property<boost::edge_weight_t, int, boost::no_property> >, std::allocator<boost::detail::sep_<void*, boost::property<boost::edge_weight_t, int, boost::no_property> > > >::_M_clear (this=0x0) at /usr/include/c++/4.4/bits/list.tcc:68
#1  0x00000000004119d2 in std::list<boost::detail::sep_<void*, boost::property<boost::edge_weight_t, int, boost::no_property> >, std::allocator<boost::detail::sep_<void*, boost::property<boost::edge_weight_t, int, boost::no_property> > > >::clear (this=0x0) at /usr/include/c++/4.4/bits/stl_list.h:1132
#2  0x000000000040fac4 in boost::clear_vertex<boost::detail::adj_list_gen<boost::adjacency_list<boost::listS, boost::listS, boost::directedS, boost::property<boost::vertex_name_t, std::string, boost::no_property>, boost::property<boost::edge_weight_t, int, boost::no_property>, boost::no_property, boost::listS>, boost::listS, boost::listS, boost::directedS, boost::property<boost::vertex_name_t, std::string, boost::no_property>, boost::property<boost::edge_weight_t, int, boost::no_property>, boost::no_property, boost::listS>::config> (u=0x0, g_=...) at boost_1_43_0/boost/graph/detail/adjacency_list.hpp:633
#3  0x000000000040e7a5 in boost::detail::graph::mutate_graph_impl<boost::adjacency_list<boost::listS, boost::listS, boost::directedS, boost::property<boost::vertex_name_t, std::string, boost::no_property>, boost::property<boost::edge_weight_t, int, boost::no_property>, boost::no_property, boost::listS> >::do_remove_vertex (this=0x7fffffffe520, node=...)
    at boost_1_43_0/boost/graph/graphviz.hpp:767
#4  0x00007ffff7b6ab12 in boost::read_graphviz_detail::translate_results_to_graph (r=..., mg=0x7fffffffe520) at ../../../libs/graph/src/read_graphviz_new.cpp:782
#5  0x00007ffff7b6b314 in boost::detail::graph::read_graphviz_new (str=..., mg=0x7fffffffe520) at ../../../libs/graph/src/read_graphviz_new.cpp:830
#6  0x000000000040bc1f in boost::read_graphviz_new<boost::adjacency_list<boost::listS, boost::listS, boost::directedS, boost::property<boost::vertex_name_t, std::string, boost::no_property>, boost::property<boost::edge_weight_t, int, boost::no_property>, boost::no_property, boost::listS> > (str=..., graph=..., dp=..., node_id=...)
    at boost_1_43_0/boost/graph/detail/read_graphviz_new.hpp:103
#7  0x000000000040b243 in boost::read_graphviz<std::istream_iterator<char, char, std::char_traits<char>, long>, boost::adjacency_list<boost::listS, boost::listS, boost::directedS, boost::property<boost::vertex_name_t, std::string, boost::no_property>, boost::property<boost::edge_weight_t, int, boost::no_property>, boost::no_property, boost::listS> > (
    user_first=..., user_last=..., graph=..., dp=..., node_id=...) at boost_1_43_0/boost/graph/graphviz.hpp:910
#8  0x000000000040aa18 in boost::read_graphviz<boost::adjacency_list<boost::listS, boost::listS, boost::directedS, boost::property<boost::vertex_name_t, std::string, boost::no_property>, boost::property<boost::edge_weight_t, int, boost::no_property>, boost::no_property, boost::listS> > (in=..., graph=..., dp=..., node_id=...)
    at boost_1_43_0/boost/graph/graphviz.hpp:922
#9  0x00000000004086a9 in test_graph_read_write (filename=...) at graphviz.cpp:41
#10 0x0000000000408814 in main () at graphviz.cpp:52

有什么想法???因为我很迷茫。

提前致谢!

【问题讨论】:

  • 这似乎是一个不同的问题 - 尝试在 valgrind 下运行它。
  • 叹息,这些堆损坏问题只是 SO 的一个无底洞。每个人都以自己的方式破坏它,它曾经是一个骗局吗?投票结束时“过于本地化”,懒得尝试找到通用答案。
  • 我最好的猜测:检查变量 v 中包含的内容。它是否指向堆?它是否被函数 clear_vertex 以任何方式修改过?您似乎有可能在第二行破坏有关对象的信息,然后尝试在第三行使用它。不知道是不是这样,但这就是我要开始的地方。
  • 嗯,它看起来不像堆栈损坏。然而,它看起来确实像某些东西没有被正确初始化,因为 NULL 指针被传递给了一个函数,并且它看起来像指向 std::list 的指针,调用了哪个 clear() 方法并最终在取消引用“this”时崩溃,这是0x0: #0 0x000000000040b87f in std::_List_base<...>::_M_clear (this=0x0) #1 0x00000000004119d2 in std::list...::clear (this=0x0)... #2 0x000000000040fac4 in . .. (u=0x0, g_=...)...

标签: c++ boost stl graphviz


【解决方案1】:

问题是当 Read Graphviz 函数读取点文件时,它不会以相同的顺序创建 DFG,从而破坏了我的删除函数。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-02-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-01
    • 1970-01-01
    相关资源
    最近更新 更多