Game freezes after certain time of function call

I am making game using SDL for the first time. Anyway, I programmed a game
that is reading map from the file,
now, I added special tile, which when collided with player, loads the other
level(that special tile is some sort of tunnel),anyway, for some reason
after going 7 times throuigh the tunnels game just freeze. And I have been
looking for problem whole day without any success, so I decided to look for
help here, I archived, the source code and resources necessary for game in
archive, here: http://www.sendspace.com/file/nit9ds please compile the game
and take a look, thanks.–
View this message in context: http://www.nabble.com/Game-freezes-after-certain-time-of-function-call.-tp19945175p19945175.html
Sent from the SDL mailing list archive at Nabble.com.

2008/10/12 systat at net.hr :

I am making game using SDL for the first time. Anyway, I programmed a game
that is reading map from the file,
now, I added special tile, which when collided with player, loads the other
level(that special tile is some sort of tunnel),anyway, for some reason
after going 7 times throuigh the tunnels game just freeze. And I have been
looking for problem whole day without any success, so I decided to look for
help here, I archived, the source code and resources necessary for game in
archive, here: http://www.sendspace.com/file/nit9ds please compile the game
and take a look, thanks.

Quick looking at your code, found that file “up.zzp” is missing. (a
tip: always verify in the code if the file you tried to load was
really loaded, displaying some warning or error message if it wasn’t)

Second, your function ‘loadLevel’ seems strange, better if writed with
{} blocks (as bellow):

//It reads data from file, and creates level
void loadLevel(string filename)
{
ifstream a(filename.c_str());

if(!a)
{
cerr << "Error: Can’t open file: " << filename << endl;
return;
}
for(int i=0;i<12;i++)
{
for(int v=0;v<16;v++)
{
a >> map[i][v];
}
}
a.close();
}

Third: Some function names make it hard to understand what you want
them to do (‘Blah’ function to blit tiles on the screen??)

I recommend you doing some debug with gdb (or with some printf/cerr on
the code) at your program and see if you can get the error(s)…

[ ]'s
Farrer

Hiyya, I want to point you to learn how to fish instead of handing you a fish. Your code style looks like a first poke at it which is not a poblem. Take a look at the following and research the function names as needed.

ofstream fout(“testX3.txt”);
fout << “testx3 >main accessed” << endl;

screen=SDL_SetVideoMode(700,500,16,SDL_HWSURFACE|SDL_DOUBLEBUF|SDL_RESIZABLE);
if ( screen == NULL )
{printf(“Unable to set 700x500 video screen: %s\n”, SDL_GetError()); exit(1);}

int main(int argc, TCHAR *argv[])

//get user preferances
ifstream pref(“data/config.txt”);
if (pref.fail())
{fout << “Loading config file failed” << endl;}
i = 0;
while (pref >> nextoken)
{
if (i < 20)//in case of hacking
{
config_line[i] = nextoken;
fout << “testx9 >” << config_line[i] << endl;
i++;
}
}
pref.close();

Maybe you can do better than me but this code is worth understanding to save you time and effort on a regular basis. Woot

---- Guilherme Farrer wrote:=============
2008/10/12 systat at net.hr :

I am making game using SDL for the first time. Anyway, I programmed a game
that is reading map from the file,
now, I added special tile, which when collided with player, loads the other
level(that special tile is some sort of tunnel),anyway, for some reason
after going 7 times throuigh the tunnels game just freeze. And I have been
looking for problem whole day without any success, so I decided to look for
help here, I archived, the source code and resources necessary for game in
archive, here: http://www.sendspace.com/file/nit9ds please compile the game
and take a look, thanks.

Quick looking at your code, found that file “up.zzp” is missing. (a
tip: always verify in the code if the file you tried to load was
really loaded, displaying some warning or error message if it wasn’t)

Second, your function ‘loadLevel’ seems strange, better if writed with
{} blocks (as bellow):

//It reads data from file, and creates level
void loadLevel(string filename)
{
ifstream a(filename.c_str());

if(!a)
{
cerr << "Error: Can’t open file: " << filename << endl;
return;
}
for(int i=0;i<12;i++)
{
for(int v=0;v<16;v++)
{
a >> map[i][v];
}
}
a.close();
}

Third: Some function names make it hard to understand what you want
them to do (‘Blah’ function to blit tiles on the screen??)

I recommend you doing some debug with gdb (or with some printf/cerr on
the code) at your program and see if you can get the error(s)…

[ ]'s
Farrer


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org