SDL error-Process terminated with status 3 (* minute(s), * second(s))

Started by
3 comments, last by MarioRossi 9 years, 10 months ago

Hello,

First of all: I'm a student with 2 years of experience in Java that still does not have idea if it's matrix[x][y] or matrix[y][x] so this error might be easy to fix or just dumb on my part, sorry if it is.

Okay, so i'm making a "port" of a rougue-like game i made in java 5-6 months ago becouse i found out that c++ with the right packages is way better... i finally found a way to make my code work but it gives a strange error when i run it (I'm using SDL), it says "Process terminated with status 3 (0 minute(s), 0 second(s))". the code is:

Main.cpp:


#include "SDL/SDL.h"
#include "SDL/SDL_image.h"
#include "bin/Graphic.h"
#include <math.h>
#include <string>
#include <fstream>

const int MAP_SIZE = 100;
const int LINE_SIZE = 10;
SDL_Surface *screen=NULL;
SDL_Surface *block_textures=NULL;
class Blocco
{
    public:
        SDL_Rect *sprite;
        int x,y;
        bool solid;
        int id;
        Blocco(){}
        Blocco(SDL_Rect *_sprite,int _x,int _y,bool _solid,int _id)
        {
            this->sprite = _sprite;
            this->x=_x;
            this->y=_y;
            this->solid=_solid;
            this->id=_id;
        }
        void show(SDL_Surface *source,SDL_Surface *destination)
        {
            apply_surface(this->x,this->y,source,destination,this->sprite);
        }
};
Blocco mappa[10][10];
class Player:public Blocco
{
    public:
        int health;
        int max_health;
        Player(SDL_Rect *_sprite,int _x,int _y,bool _solid,int _id,int _health,int _max_health):Blocco(_sprite,_x,_y,_solid,_id)
        {
            this->health = _health;
            this->max_health = _max_health;
        }
};
void load_map(Blocco loadedMap[][10],std::string filename,int maxTile)
{
    std::ifstream map(filename.c_str(),std::ifstream::in);
    int x=0;
    int y=0;

    for(int t=0;t<MAP_SIZE;t++)
    {
        int tileType=-1;
        map>>tileType;

        if((tileType>=0)&&(tileType<maxTile))
        {
            SDL_Rect *temp=NULL;temp->x=(tileType*16);temp->y=0;temp->h=16,temp->w=16;
            bool solid;
            if(tileType==0||tileType==2){solid=true;}else{solid=false;}
            Blocco supp(temp,x,y,solid,tileType);
            loadedMap[x][y]=supp;
            x++;
            if(x==LINE_SIZE) //da testare!
            {
                x=0;
                y++;
            }
        }
    }
    map.close();
}
void refresh()
{
    for(int y=0;y<LINE_SIZE;y++)
    {
        for(int x=0;x<LINE_SIZE;x++)
        {
            mappa[x][y].show(block_textures,screen);
        }
    }
}

int main(int argc,char *argv[])
{
    SDL_Init(SDL_INIT_EVERYTHING);
    screen = SDL_SetVideoMode(160,160,32,SDL_SWSURFACE);
    block_textures = load_image("textures/blocks.bmp");
    load_map(mappa,"maps/map01.txt",MAP_SIZE);
    refresh();
    SDL_Delay(10000);
    SDL_Quit();
    return 0;
}

Graphic.h:


#include "SDL/SDL.h"
#include "SDL/SDL_image.h"
#include <string>

SDL_Surface* load_image(std::string filename)
{
	SDL_Surface* loadedImage = NULL;
	SDL_Surface* optimizedImage = NULL;
	loadedImage = IMG_Load(filename.c_str());
	if(loadedImage != NULL)
	{
		optimizedImage = SDL_DisplayFormat(loadedImage);
		SDL_FreeSurface(loadedImage);
	}
	if(optimizedImage!=NULL)
	{
		Uint32 colorkey = SDL_MapRGB(optimizedImage->format,0,0xFF,0xFF);
		SDL_SetColorKey(optimizedImage,SDL_SRCCOLORKEY,colorkey);
	}
	return optimizedImage;
}
void apply_surface(int x,int y,SDL_Surface* source,SDL_Surface* destination)
{
	SDL_Rect offset;
	offset.x = x;
	offset.y = y;
	SDL_BlitSurface(source,NULL,destination,&offset);
}
void apply_surface(int x,int y,SDL_Surface *source,SDL_Surface *destination,SDL_Rect *clip)
{
	SDL_Rect offset;
	offset.x = x;
	offset.y = y;
	SDL_BlitSurface(source,clip,destination,&offset);
}

I know it's messy and i'll move the function and classes around once i polish it up (or maybe i should do it now?)

Anyway, after a bit of testing and troubleshooting i found the error to be in the function "load_map" as expected (I'm not really sure how to use the file interactions in C++)... I googled the problem and a lot of people say it's an empty pointer but i've checked and it dowsn't look like it, anyone has any idea of how to fix this? biggrin.png

Edit: I'm using Code::Blocks and MinGw for editing and compiling, if you need any description of the code (what it does, why is it like this ecc) I'll try to provide more information as soon as I check the post

Advertisement
The only problem I can spot is that temp is null when you are trying to assign to temp->x, etc.

Thanks for the reply!
Now it works, it was just some problem with the empty pointer (but my code still doesn't do what i want )= )

The term you are looking for is 'null pointer'. 'Empty pointer' is not really a standing expression and might result in misunderstandings.

Thanks for the explanation, I'm not very good with english so sometimes i just misspell or I can't find the right words.
btw: now my program works fully :D

This topic is closed to new replies.

Advertisement