Click here to Skip to main content
15,881,413 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
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 :

C++
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
C++
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;
    }
Posted
Comments
Sergey Alexandrovich Kryukov 12-Dec-14 13:04pm    
"Crash" is not a proper term for a software developer, can only be heard from a user having no access to anything.
A software developer can see the exception, its message and call stack, knows in what like a problem happened, and other detail...
—SA
KarstenK 13-Dec-14 12:57pm    
My tip is that you are over-releasing memory. Write TRACE-code in ALL destructors and clean up all your vectors and objects explictly.
[no name] 15-Dec-14 18:35pm    
CP isn't letting me post this as a solution:

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 again 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.

I get "Oops! There was an unexpected problem adding your answer. Please try again later." Hope this helps.
Philippe Mori 17-Dec-14 22:58pm    
Have yoy tried to run the application while diagnostics turn on. I would recommand you to try the software with compiler and Library checks enabled.

Here are some links:
http://msdn.microsoft.com/en-us/library/8wtf2dfz.aspx
ttp://msdn.microsoft.com/en-us/library/aa985965.aspx
Also ensure to do as much as possible validation in code using assertion or exception.
LaxmikantYadav 18-Dec-14 7:11am    
Have you check for memory leaks in your program ?

1 solution

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.
 
Share this answer
 
v2
Comments
Philippe Mori 17-Dec-14 22:52pm    
Although it might happen sometime that the application does not works properly because it was not properly build after a change, this is very rare. It is probably memory corruption because of wrong code (double deletion, buffer overrun, using unintialized variable...)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900