调试版本只会崩溃

时间:2012-11-09 01:37:39

标签: c++ debugging boost

我只有调试崩溃。我正在使用Eclipse的gdb。 如果我没有读取它,则在将对象(不是通过引用或指针)传递给接口方法时,恰好在复制“many”(typedef std::list<boost::any> many;)成员期间发生崩溃它的复制构造函数被调用以向该方法发送副本。 我没有使用调试版本来提升,也没有使用其他外部版本,只是因为我正在编译的代码,所以,这可能是原因吗? 可能是什么原因的任何其他想法?

class Message {
public:
static const int MAX_LEVEL=5;
Message(int type=0, int destination=0);
virtual ~Message();

int type;
int destination[MAX_LEVEL];
int level;
many message;
};

崩溃的扇区,在init() Game3DWin内:(即使我在Debug模式下构建,也没有_DEBUG定义,因为我没有为libs构建Debug二进制文件)< / p>

bool Game3DWin::init(){
#ifdef _DEBUG
pluginsCfg = "lib/plugins_d.cfg";
resourcesCfg = "res/resources_d.cfg";
#elif OGRE_PLATFORM == OGRE_PLATFORM_WIN32
pluginsCfg = "lib/pluginsWin.cfg";
resourcesCfg = "res/resources.cfg";
#else
pluginsCfg = "lib/plugins.cfg";
resourcesCfg = "res/resources.cfg";
#endif
ogreRoot=boost::make_shared<Ogre::Root>(pluginsCfg, "config.cfg");
if(!(ogreRoot->restoreConfig() || ogreRoot->showConfigDialog())){
    return false;
}
window = ogreRoot->initialise(true, "Crewon CLASH!");
loadResourceCfgFile();

guiRenderer = &CEGUI::OgreRenderer::bootstrapSystem();
CEGUI::SchemeManager::getSingleton().create( "TaharezLook.scheme" );
CEGUI::System::getSingleton().setDefaultFont( "DejaVuSans-10" );
CEGUI::System::getSingleton().setDefaultMouseCursor( "TaharezLook", "MouseArrow" );
CEGUI::Window* myRoot = CEGUI::WindowManager::getSingleton().createWindow( "DefaultWindow", "_MasterRoot" );
CEGUI::System::getSingleton().setGUISheet( myRoot );

    CRengine::Message msg=CRengine::Message( (int)CRengine::MESSAGE_TYPE::INPUT_INIT );
msg.message.push_front(window);
this->broadcaster.lock()->receiveMessage( msg ); //Crash here
//Unreached code due to crash
}

broadcaster是一个指向Messageable的指针,一个接口。

class Messageable {
public:
virtual ~Messageable() {};
virtual bool receiveMessage(CRengine::Message) = 0;
};

广播器初始化(能够存储“this”智能指针的工厂方法):

Game3DWin* Game3DWin::create(boost::shared_ptr<CRengine::Messageable> caster, int processType, int order){
Game3DWin* temp= new Game3DWin(processType, order);
temp->broadcaster=caster;
bool success=temp->init();
if(!success){
    delete temp;
    temp=NULL;
}else{
    temp->checkRoom(); }
return temp;
}

以上称为:

bool MainManager::start( boost::shared_ptr<MainManager> thisMM ){
//Some code
    boost::shared_ptr<Game3DWin> win;
    win.reset( Game3DWin::create(thisMM, CRengine::MAIN_PROCESS_TYPES::PROCESS_GUI) );
//Some code
}

从main调用start(),它将指针传递给MainManager

boost::shared_ptr<CRengine::MainManager> app =boost::make_shared<CRengine::MainManager>();
        app->start(app);

消息实施:

Message::Message(int type, int destination): type(type), level(0){
for(int ii=0;ii<MAX_LEVEL;ii++){
     this->destination[ii]=-1;
}
this->destination[0]=destination;
}
Message::~Message() { }
来自OGRE 3D开源渲染引擎的

windowOgre::RenderWindow*。我尝试将其转换为(int),然后将其推入many,以防它试图调用析构函数或其他内容,但是,仍然,同样崩溃。

2 个答案:

答案 0 :(得分:0)

这是一条扩展评论,太长而无法发表评论。

Message缺少已实现的构造函数和析构函数。要么在确认问题仍然存在的同时简化课程,要么将该实施暴露给我们。

window是未知类型的变量。由于您报告为崩溃的list boost::any包含window类型,因此知道它的含义可能会有所帮助。

如果this->broadcaster.lock()已消失,

shared_ptr将为空weak_ptr。始终,始终始终shared_ptr<foo> pFoo = this->broadcaster.lock();,然后在检查它是否有效后使用pFoo(或任何名称)(在bool ean上下文中进行评估)。

boost::weak_ptr<CRengine::Messageable> caster - 你不知道这是否存在?你可能想要boost::shared_ptr,这样在创建Game3DWin时至少知道施法者存在。

同样在这里:boost::weak_ptr<MainManager> thisMM - 可能应该是shared_ptr

答案 1 :(得分:0)

问题不在于上述问题。这是因为Eclipse无法清理。这是由于使用了“外部构建器”,mingw32-make.exe,它在makefile中运行del <Filelist>而Windows7似乎对此及其参数有一些问题,因此clean没有做任何事情。 由于我使用Debug作为活动版本,因为缺少clean而导致崩溃,但当我切换到Release时,它不受影响,因为它必须重建所有内容。 手动删除<project>/Debug<project>/Release的内容解决了问题。

相关问题