2

我正在使用 boost::ptr_vector 来包含类对象的列表。

我以这种方式将对象添加到 ptr_vector 中:

parent_ptrvector.push_back(new PlanVertex(-1,-1,-1));

当初始化包含 ptr_vector 的类时,我只添加一次对象。

我从不复制向量。

我不会在向量中添加或删除对象,但我确实以这种方式对 ptr_vector 中的元素调用 setCoords 函数:

parent_ptrvector.at(i).setCoords(1,2,3);

我的问题是,当包含 ptr_vector 的类被破坏时,我似乎间歇性地遇到了分段错误。当我在运行期间对许多不同的元素调用 setCoords 时,似乎更有可能发生故障。

我收到的消息是:

munmap_chunk(): invalid pointer: 0x00007fff50016f20 ***

非常感谢您的帮助,我在下面粘贴了 gdb 回溯:

#0  0x00007ffff5d6f425 in __GI_raise (sig=<optimized out>) at ../nptl/sysdeps/unix/sysv/linux/raise.c:64
#1  0x00007ffff5d72b8b in __GI_abort () at abort.c:91
#2  0x00007ffff5dad39e in __libc_message (do_abort=2, fmt=0x7ffff5eb7748 "*** glibc detected *** %s: %s: 0x%s ***\n") at ../sysdeps/unix/sysv/linux/libc_fatal.c:201
#3  0x00007ffff5db7b96 in malloc_printerr (action=3, str=0x7ffff5eb7838 "munmap_chunk(): invalid pointer", ptr=<optimized out>) at malloc.c:5039
#4  0x00000000004cbf8d in void boost::checked_delete<PlanVertex const>(PlanVertex const*) ()
#5  0x00000000004cbf55 in void boost::delete_clone<PlanVertex>(PlanVertex const*) ()
#6  0x00000000004cbf35 in void boost::heap_clone_allocator::deallocate_clone<PlanVertex>(PlanVertex const*) ()
#7  0x00000000004cbf15 in boost::ptr_container_detail::reversible_ptr_container<boost::ptr_container_detail::sequence_config<PlanVertex, std::vector<void*, std::allocator<void*> > >, boost::heap_clone_allocator>::null_clone_allocator<false>::deallocate_clone(PlanVertex const*) ()
#8  0x00000000004cbeb5 in boost::ptr_container_detail::reversible_ptr_container<boost::ptr_container_detail::sequence_config<PlanVertex, std::vector<void*, std::allocator<void*> > >, boost::heap_clone_allocator>::null_policy_deallocate_clone(PlanVertex const*) ()
#9  0x00000000004cbe69 in void boost::ptr_container_detail::reversible_ptr_container<boost::ptr_container_detail::sequence_config<PlanVertex, std::vector<void*, std::allocator<void*> > >, boost::heap_clone_allocator>::remove<boost::void_ptr_iterator<__gnu_cxx::__normal_iterator<void**, std::vector<void*, std::allocator<void*> > >, PlanVertex> >(boost::void_ptr_iterator<__gnu_cxx::__normal_iterator<void**, std::vector<void*, std::allocator<void*> > >, PlanVertex>) ()
#10 0x00000000004cbd1b in void boost::ptr_container_detail::reversible_ptr_container<boost::ptr_container_detail::sequence_config<PlanVertex, std::vector<void*, std::allocator<void*> > >, boost::heap_clone_allocator>::remove<boost::void_ptr_iterator<__gnu_cxx::__normal_iterator<void**, std::vector<void*, std::allocator<void*> > >, PlanVertex> >(boost::void_ptr_iterator<__gnu_cxx::__normal_iterator<void**, std::vector<void*, std::allocator<void*> > >, PlanVertex>, boost::void_ptr_iterator<__gnu_cxx::__normal_iterator<void**, std::vector<void*, std::allocator<void*> > >, PlanVertex>) ()
#11 0x00000000004cbcbb in boost::ptr_container_detail::reversible_ptr_container<boost::ptr_container_detail::sequence_config<PlanVertex, std::vector<void*, std::allocator<void*> > >, boost::heap_clone_allocator>::remove_all() ()
#12 0x00000000004cbc38 in boost::ptr_container_detail::reversible_ptr_container<boost::ptr_container_detail::sequence_config<PlanVertex, std::vector<void*, std::allocator<void*> > >, boost::heap_clone_allocator>::~reversible_ptr_container() ()
#13 0x00000000004cbc15 in boost::ptr_sequence_adapter<PlanVertex, std::vector<void*, std::allocator<void*> >, boost::heap_clone_allocator>::~ptr_sequence_adapter() ()
#14 0x00000000004cbbf5 in boost::ptr_vector<PlanVertex, boost::heap_clone_allocator, std::allocator<void*> >::~ptr_vector() ()
#15 0x00000000004cbbd5 in boost::ptr_vector<PlanVertex, boost::heap_clone_allocator, std::allocator<void*> >::~ptr_vector() ()
#16 0x00000000004cb8ec in PathPlanData::~PathPlanData() ()
#17 0x00000000004cb825 in PathPlanData::~PathPlanData() ()
4

0 回答 0