我遇到了这样的崩溃:
#0 0x90b05955 in __gnu_debug::_Safe_iterator_base::_M_detach
#1 0x90b059ce in __gnu_debug::_Safe_iterator_base::_M_attach
#2 0x90b05afa in __gnu_debug::_Safe_sequence_base::_M_detach_all
#3 0x000bc54f in __gnu_debug::_Safe_sequence_base::~_Safe_sequence_base at safe_base.h:170
#4 0x000aac05 in __gnu_debug::_Safe_sequence<__gnu_debug_def::vector<boost::signals::trackable const*, std::allocator<boost::signals::trackable const*> > >::~_Safe_sequence at safe_sequence.h:97
#5 0x000ac9c1 in __gnu_debug_def::vector<boost::signals::trackable const*, std::allocator<boost::signals::trackable const*> >::~vector at vector:95
#6 0x000acf65 in boost::signals::detail::slot_base::data_t::~data_t at slot.hpp:32
#7 0x000acf8f in boost::checked_delete<boost::signals::detail::slot_base::data_t> at checked_delete.hpp:34
#8 0x000b081e in boost::detail::sp_counted_impl_p<boost::signals::detail::slot_base::data_t>::dispose at sp_counted_impl.hpp:78
#9 0x0000a016 in boost::detail::sp_counted_base::release at sp_counted_base_gcc_x86.hpp:145
#10 0x0000a046 in boost::detail::shared_count::~shared_count at shared_count.hpp:217
#11 0x000a9fb0 in boost::shared_ptr<boost::signals::detail::slot_base::data_t>::~shared_ptr at shared_ptr.hpp:169
#12 0x000aa459 in boost::signals::detail::slot_base::~slot_base at slot.hpp:27
#13 0x000aad07 in boost::slot<boost::function<bool ()(char, int)> >::~slot at slot.hpp:105
#14 0x001b943b in main at vermes.cpp:102
这是代码:
#include <boost/signal.hpp>
#include <boost/lexical_cast.hpp>
#include <boost/function.hpp>
#include <boost/bind.hpp>
bool dummyfunc(char,int) { return false; }
int main(int argc, char **argv)
{
boost::signal<bool (char, int)> myslot;
myslot.connect(0, &dummyfunc);
return 0;
}
这是我第一次使用 Boost,而且我对我试图在这里移植的项目的代码也完全陌生。
这就是为什么我想问一下这种崩溃是否可以由 Boost 以任何方式解释,或者它是否一定与 Boost 无关。
我已经尝试了解崩溃本身,但不知何故被卡住了。似乎将要在此处删除的 std::vector 可能被搞砸了(搞砸 = 内存损坏)。该向量是 slot_base::data_t 的成员。删除是在 slot_base::shared_ptr 的析构函数中完成的。所以也许 shared_ptr 也被搞砸了 - 所以甚至整个 slot_base 都被搞砸了。但是在我拥有的代码中,我真的看不出那个内存可能会被搞砸的原因。这甚至是myslot建成后的第一次访问。
另外:我也不太明白为什么在我进行连接时会在这里调用 ~slot_base()。但我也没有找到连接成员函数。那是某个地方的魔法巨魔吗?