c ++关闭,崩溃。 [英] c++ on close, crash.

查看:123
本文介绍了c ++关闭,崩溃。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用c ++开发游戏。编译和运行时一切正常但当我退出游戏时,崩溃发生在一个Windows消息框中,说qwerty.exe已停止工作。我在向我的班级添加一个新的变量成员时发现了崩溃。删除新成员或任何成员似乎使崩溃消失(一个非常糟糕的解决方案)加上它只在崩溃时在调试模式下崩溃(我使用Code :: block)编译器和调试器似乎都注意到了崩溃。我没有收到任何反馈。与记忆有什么关系?







这里我的Map.h:



  class 地图: public  EmptyMap 
{
public
Map();
virtual ~Map();
void init(Player * iplayer,Player * iplayer2);

void operator =( const Map& other){Mobjects = other.Mobjects;}
void setSubMab(Map * imap2,Map * imap3);
void setSubMab(Map * imap2);
Mob& getMob( int id){ return mobs [id];}
// void setMapLayer(int value){mapLayer = value;}
protected
int mapLayer; // 这是我在崩溃时添加的变量。
int nbMaps;
EmptyMap * map2;
EmptyMap * map3;
std :: vector< int>瓷砖;
std :: vector< GameObject *> Mobjects;
std :: vector< GameObject *> Sobjects;
std :: vector< GameObject *> Sortobjects;
std :: vector< GameObject *> NoSortobjects;
std :: vector< StaticObject> staticTest;
std :: vector< Mob>小怪;

玩家*玩家;
Player * player2;

Coordsi mapSizeTile;
Coordsi mapSizePixel;
Coordsi tileSize;
};











这里map.cpp

<前lang =c ++>地图::地图()
{
nbMaps = 1 ;
}
void Map :: setSubMab(Map * imap2,Map * imap3){
nbMaps = 3 ;
map2 = imap2;
// map2-> setMapLayer(2);
map3 = imap3 ;
// map3-> setMapLayer(3);
}
void Map :: setSubMab(Map * imap2){
nbMaps = 2 ;
map2 = imap2;
// map2-> setMapLayer(2);
}
Map :: ~Map()
{
}
void Map :: init(Player * iplayer,Player * iplayer2 ){
// Mobjects.push_back(iplayer);
// Mobjects.push_back(iplayer2);
Sortobjects.push_back(iplayer);
Sortobjects.push_back(iplayer2);
player = iplayer;
player2 = iplayer2;
}

解决方案

删除所有obj文件并重建。



如果您正在使用make文件,请尝试make clean,然后单击make或make all。



如果您使用的是Visual Studio ,尝试重建 - 所有。



链接到从早期版本的头文件创建的目标文件时发生奇怪的事情。



更好的是,更新makefile依赖项,以便头文件编辑导致重新编译适当的源文件。


I am working on a game in c++. Everything works fine when compiling and running but when I quit the game, the crash occurs with a windows message-box saying qwerty.exe as stopped working. I discovered the crash when adding a new variable member to my class. Removing the new or any member seems to make the crash disappear (A very bad solution) plus it only crashes while in debug mode not in release(I use Code::block) The compiler nor the debugger seem to notice the crash. I receive no feedback. Something to do with memory?



Here my Map.h :

class Map : public EmptyMap
    {
        public:
            Map();
            virtual ~Map();
            void init(Player *iplayer, Player *iplayer2);

            void operator =(const Map& other){Mobjects = other.Mobjects;}
            void setSubMab( Map *imap2, Map *imap3 );
            void setSubMab( Map *imap2 );
            Mob& getMob(int id){return mobs[id];}
           // void setMapLayer(int value){mapLayer = value;}
        protected:
            int mapLayer; // this is the variable that I added when is crashed.
            int nbMaps;
            EmptyMap *map2;
            EmptyMap *map3;
            std::vector<int> tiles;
            std::vector<GameObject*> Mobjects;
            std::vector<GameObject*> Sobjects;
            std::vector<GameObject*> Sortobjects;
            std::vector<GameObject*> NoSortobjects;
            std::vector<StaticObject> staticTest;
            std::vector<Mob> mobs;
    
            Player *player;
            Player *player2;
    
            Coordsi mapSizeTile;
            Coordsi mapSizePixel;
            Coordsi tileSize;
    };






Here map.cpp

Map::Map()
    {
        nbMaps = 1;
    }
    void Map::setSubMab( Map *imap2, Map *imap3 ){
        nbMaps = 3;
        map2 = imap2;
        //map2->setMapLayer(2);
        map3 = imap3;
        //map3->setMapLayer(3);
    }
    void Map::setSubMab( Map *imap2 ){
        nbMaps = 2;
        map2 = imap2;
        //map2->setMapLayer(2);
    }
    Map::~Map()
    {
    }
    void Map::init(Player *iplayer, Player *iplayer2){
        //Mobjects.push_back(iplayer);
        //Mobjects.push_back(iplayer2);
        Sortobjects.push_back(iplayer);
        Sortobjects.push_back(iplayer2);
        player = iplayer;
        player2 = iplayer2;
    }

解决方案

Erase all obj files and rebuild.

If you're using a make file, try "make clean" followed by "make" or "make all".

If you're using Visual Studio, try a rebuild-all.

Strange things happen when linking against an object file created from an earlier version of the header file.

Even better, update the makefile dependencies so that header file edits cause appropriate sources files to be re-compiled.


这篇关于c ++关闭,崩溃。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆