Sign in to follow this  

Code::Blocks: Process terminated with status -1073741819

This topic is 1272 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello everyone,

So... today I was expanding my game a bit to make it load 25x25 maps instead of 10x10. here's the function I use for loading the maps:

void load_map(Blocco loadedMap[][10],std::string filename,int maxTile) //filename = "map00.txt", the map to read, maxTIle= the maximum ID for a tile accepted
{ //loadedMap = a matrix to hold the Blocks for later use (like printing the map/ineteractions)
    std::ifstream map(filename.c_str(),std::ifstream::in);
    int x=0;
    int y=0;

    for(int t=0;t<MAP_SIZE;t++) //MAP_SIZE = how many blocks are in the map
    {
        int tileType=-1;
        map>>tileType;

        if((tileType>=0)&&(tileType<maxTile))
        {
            SDL_Rect *temp = new SDL_Rect(); //Rectangle to mark wich sprite to use for the block
            temp->x=(tileType*BLOCK_SIZE);temp->y=0;temp->h=BLOCK_SIZE,temp->w=BLOCK_SIZE;
            bool solid;
            if(tileType==2||tileType==3||tileType==5){solid=true;}else{solid=false;} //wheater the block is solid or not
            Blocco supp(temp,x,y,solid,tileType); //Blocco = Block in Italian lol, you give it the sprite, coordinates and the ID
            loadedMap[x][y]=supp;
            x++;
            if(x==LINE_SIZE)
            {
                x=0;
                y++;
            }
        }
    }
    //STARTS READING PLAYER COORDS
    int px,py;
    map>>px; //READS X
    map>>py; //READS Y
    SDL_Rect *pSprite = new SDL_Rect();pSprite->x=0;pSprite->y=0;pSprite->h=BLOCK_SIZE;pSprite->w=BLOCK_SIZE; //CREATES THE SPRITE FOR THE PLAYER
    player = new Player(pSprite,px,py,true,0,100,100); //Player is similar to a block but has current_health and max_health (100 and 100 in this case)
    
//START READING KEYS
    
    int nKeys; //How Many keys are there
    int xKey=0; //
    int yKey=0; //The coordinates of the key
    int keyType;
    std::string nameKey;
    std::string descKey;
    map>>nKeys;
    for(int i=0;i<nKeys;i++)
    {
        map>>xKey; //Reads how many Keys to load
        map>>yKey; //
        map>>keyType; //The type of key loaded (green key, red key and blue key
        SDL_Rect *kSprite = new SDL_Rect();kSprite->x=96+(keyType*BLOCK_SIZE);kSprite->y=0;kSprite->w=BLOCK_SIZE;kSprite->h=BLOCK_SIZE;
        switch(keyType) //Just sets the name and desc based on the type of key
        {
            case 1: nameKey="GreenKey";
                    descKey="a green key";
                    break;
            case 2: nameKey="BlueKey";
                    descKey="a blue key";
                    break;
            case 3: nameKey="RedKey";
                    descKey="a red key";
                    break;
        }
        Key* add = new Key(kSprite,xKey,yKey,false,true,keyType,nameKey,descKey);
        keys.push_back(add); //adds the key* to a vector<Key*> that holds them
    }
    
    map.close();
}

And this is the file I read:

02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 //
02 01 01 01 02 01 01 01 01 01 02 01 01 01 01 01 01 01 02 01 02 01 02 01 02 //
02 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 02 02 02 02 02 02 02 //
02 01 01 01 02 01 01 01 01 01 02 01 01 01 01 01 01 01 01 01 01 01 01 01 02 //
02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 01 02 02 //
02 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 04 01 01 01 01 01 01 01 02 //
02 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 04 01 01 01 01 01 01 01 02 //
02 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 02 02 02 02 02 02 02 02 02 //
02 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 02 01 01 01 02 01 01 01 02 //
02 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 02 01 01 01 02 // The actual map: 625 Blocks(IDs), 25 per line
02 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 02 02 02 02 02 01 01 01 02 //
02 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 02 01 01 01 02 //
02 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 02 01 01 01 02 //
02 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 02 //
02 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 02 //
02 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 02 01 01 01 02 //
02 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 02 01 01 01 02 //
02 01 01 01 01 01 01 01 01 02 02 02 04 02 02 02 02 02 02 02 02 01 01 01 02 //
02 01 01 01 01 01 01 01 01 02 01 01 01 01 01 01 01 01 01 01 01 01 01 01 02 //
02 01 01 01 01 01 01 01 01 02 01 01 01 01 01 01 01 01 01 01 01 01 01 01 02 //
02 02 02 02 02 01 01 01 01 02 01 01 01 01 01 01 01 01 01 01 01 01 01 01 02 //
02 01 01 01 02 01 01 01 01 02 01 01 01 01 01 01 01 01 01 01 01 01 01 01 02 //
02 01 01 01 01 01 01 01 01 02 01 01 01 01 01 01 01 01 01 01 01 01 01 01 02 //
02 01 01 01 02 01 01 01 01 02 01 01 01 01 01 01 01 01 01 01 01 01 01 01 02 //
02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 //
01 03 //Player Coords
06 //How many keys are there
19 01 01 //Key 1: x19 y01 type:Green
21 01 02 //Key 2: x21 y01 ....
23 01 03 ...
19 08 01 ...
01 22 03
20 22 02

I modified the constants: MAP_SIZE and LINE_SIZE from 100 and 10 to 625 and 25 and now the program crashes when it gets to the function load map with this error: "Process terminated with status -1073741819 (0 minute(s), 5 second(s))", am I missing something? :S

Edited by MarioRossi

Share this post


Link to post
Share on other sites

Would make it easier to review if you add some comments to the code.

This is always a good idea if you show others the code. I am only a simple software enginneer and have no clue about the idea behind your code. Comments are hints for any software engineer while read it.

Share this post


Link to post
Share on other sites

Oh... I totally overlooked it, now I feel dumb

 

One way you can eliminate that sort of error in the future is to not hardcode "magic" numbers like that.  Either use a #define or declare a const int  to give the value a name.  Then if you change the map size, you only need to make an alteration in one place.

Edited by LennyLen

Share this post


Link to post
Share on other sites

This topic is 1272 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this