2009-12-01 37 views
0

我收到这样的崩溃:Boost:boost :: slot <> ::〜slot中崩溃的原因是什么?

#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无关。

我已经尝试了解崩溃本身,但我被卡住了。看起来,可能std :: vector,这将被删除在这里,搞砸了(搞砸了=内存损坏)。该矢量是slot_base :: data_t的成员。删除操作在slot_base :: shared_ptr的析构函数中完成。所以也许shared_ptr也被搞砸了 - 所以也许整个slot_base被搞砸了。但是在我所拥有的代码中,我并不认为这个内存可能会被搞砸的原因。在建造myslot之后,它甚至是第一个访问。

此外:我也不是很明白的是为什么在我进行连接时调用〜slot_base()。但我也没有找到连接成员函数。这是一个神奇的玛格罗某处吗?

+1

我没有看到你的代码给出了什么错误,但应该注意的是,通过做一些完全不相关的东西来破坏'vector'是微不足道的 - 你的其他代码可能会有缓冲区溢出,并且会“溢出“插入向量(或shared_ptr,或插槽...)。 – 2009-12-01 02:39:19

+0

GConsole :: init()小到足以添加到这个问题吗?如果它很大,你能做多少,仍然会出现这个错误? – 2009-12-01 16:14:51

+0

我已经将整个事物简化为一个非常简单的测试用例。看起来这与我的其他代码非常相关。 – Albert 2009-12-02 11:54:45

回答

1

我发现了这个问题。当我启用这些预处理器定义(我的Xcode确实是在调试配置默认),它崩溃:

-D _GLIBCXX_DEBUG=1 
-D _GLIBCXX_DEBUG_PEDANTIC=1 

我猜编译没有那些并导致这样的问题,因为STL结构(如矢量)升压(的bjam)编译时使用或不使用二进制形式看起来不同。

0

听起来像你的GConsole类不是从boost::trackable派生。

当一个信号绑定到一个成员函数时,它总是期望该成员的对象存在。

您可以在成员函数的所有者被销毁时明确断开信号,也可以从boost::trackable中派生出对象,该对象将在对象被销毁时自动进行维护。

+0

但是GConsole存在于这一点上。 GConsole :: init()函数在构建GConsole之后调用。此外,它在一开始就是正确的,所以崩溃发生在连接插槽,而不是断开连接。 – Albert 2009-12-01 13:28:55

+0

另一个问题可能是:为什么〜slot_base()在这里被调用,当我做一个slot.connect? – Albert 2009-12-01 13:33:12