0

我有 ObjRecRANSAC 类,它具有以下 std::list 成员:

    std::list<OrientedPointPair> sampled_oriented_point_pairs_;

OrientedPointPair 是 ObjRecRANSAC 内部定义的一个类,如下所示:

    class OrientedPointPair
    {
        public:
          OrientedPointPair (const float *p1, const float *n1, const float *p2, const float *n2)
          : p1_ (p1), n1_ (n1), p2_ (p2), n2_ (n2)
          {
          }

          virtual ~OrientedPointPair (){}

        public:
          const float *p1_, *n1_, *p2_, *n2_;
    };

一旦构造了 ObjRecRANSAC 类。调用sample_oriented_point_pairs_.clear()导致段错误。

我尝试使用 gdb 来调试错误,这就是我得到的:

print sampled_oriented_point_pairs_
$4 = {<std::_List_base<pcl::recognition::ObjRecRANSAC::OrientedPointPair, std::allocator<pcl::recognition::ObjRecRANSAC::OrientedPointPair> >> = {
    _M_impl = {<std::allocator<std::_List_node<pcl::recognition::ObjRecRANSAC::OrientedPointPair> >> = {<__gnu_cxx::new_allocator<std::_List_node<pcl::recognition::ObjRecRANSAC::OrientedPointPair> >> = {<No data fields>}, <No data fields>}, _M_node = {
        _M_next = 0x3f7d70a4, _M_prev = 0x0}}}, <No data fields>}
(gdb) s
std::list<pcl::recognition::ObjRecRANSAC::OrientedPointPair, std::allocator<pcl::recognition::ObjRecRANSAC::OrientedPointPair> >::clear (this=0x7fffffffdb38) at /usr/include/c++/4.6/bits/stl_list.h:1197
1197            _Base::_M_clear();
(gdb) s
std::_List_base<pcl::recognition::ObjRecRANSAC::OrientedPointPair, std::allocator<pcl::recognition::ObjRecRANSAC::OrientedPointPair> >::_M_clear (this=0x7fffffffdb38) at /usr/include/c++/4.6/bits/list.tcc:70
70        _Node* __cur = static_cast<_Node*>(this->_M_impl._M_node._M_next);
(gdb) print __cur
$5 = (
    std::_List_base<pcl::recognition::ObjRecRANSAC::OrientedPointPair, std::allocator<pcl::recognition::ObjRecRANSAC::OrientedPointPair> >::_Node *) 0x7a6c60
(gdb) print *__cur
$6 = {<std::__detail::_List_node_base> = {_M_next = 0x50a330, _M_prev = 0x7fff00000000}, _M_data = {_vptr.OrientedPointPair = 0x0, 
    p1_ = 0x7fffef9364d8, n1_ = 0x1b280e0, p2_ = 0x1ed2f00, n2_ = 0x1ed2f00}}
(gdb) s
71        while (__cur != &this->_M_impl._M_node)
(gdb) s
73        _Node* __tmp = __cur;
(gdb) s
74        __cur = static_cast<_Node*>(__cur->_M_next);
(gdb) print __cur
$7 = (
    std::_List_base<pcl::recognition::ObjRecRANSAC::OrientedPointPair, std::allocator<pcl::recognition::ObjRecRANSAC::OrientedPointPair> >::_Node *) 0x3f7d70a4
(gdb) print *__cur
** Cannot access memory at address 0x3f7d70a4 **
(gdb) print &this->_M_impl._M_node
$8 = (std::__detail::_List_node_base *) 0x7fffffffdb38
(gdb) s

Program received signal SIGSEGV, Segmentation fault.
0x00000000004c1608 in std::_List_base<pcl::recognition::ObjRecRANSAC::OrientedPointPair, std::allocator<pcl::recognition::ObjRecRANSAC::OrientedPointPair> >::_M_clear (this=0x7fffffffdb38) at /usr/include/c++/4.6/bits/list.tcc:74
74        __cur = static_cast<_Node*>(__cur->_M_next);

显然这是问题所在:Cannot access memory at address 0x3f7d70a4

我也不明白为什么在第 70 行执行之前的__cur初始地址设置为 0x7a6c60当前甚至还没有被声明。同样在执行第 70 行之前打印*__cur似乎返回了一个值,这也是一个惊喜。

sampled_orient_point_pair_ 只是在类中声明,并没有在构造函数中初始化。这可能是问题吗?但是,这段代码以前可以工作吗?

4

0 回答 0