我得到了这样一个崩溃:
#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()在这里被调用。但是我也没有找到connect-connect函数。那是个神奇的马克罗吗?
发布于 2009-12-03 20:38:44
我找到问题了。当我启用这些预处理器定义时(我的Xcode在Debug配置中默认这样做),它崩溃了:
-D _GLIBCXX_DEBUG=1
-D _GLIBCXX_DEBUG_PEDANTIC=1我猜Boost (bjam)没有使用它们编译,这会导致这样的问题,因为STL结构(如vector)在使用或不使用它进行编译时,看起来在二进制形式上是不同的。
发布于 2009-12-01 14:23:11
听起来您的GConsole类不是从boost::trackable派生的。
当一个信号被绑定到成员函数时,它期望成员的对象始终存在。
您可以在成员函数的所有者被销毁时显式地断开信号,也可以从boost::trackable派生对象,它将在对象被销毁时自动进行维护。
https://stackoverflow.com/questions/1823605
复制相似问题