Please Help Game Crashes After A Couple Of Minutes


mac-10

Still Fresh
Joined
Oct 27, 2006
Messages
56
Age
45
Website
Visit site
Hi All

I have been writing a little game to get my head into game programming.
I have to admit it has been a bit of a struggle to produce something with
a bit of polish. I have nearly finish my maze "game". its not much
of a game :) but it should help me put together a frame work that
I can use in the future.

have hit a bit of a snag though. the game seem to run just fine for a couple of
minutes and then crash. I think it has something to do with how I am drawing
to the game surface.

I am using

SDL_Flip(game->screen);
SDL_FreeSurface(game->screen);

had thought that calling FreeSurface would clear the game surface.
its as if it is creating a new surface every time the draw function is call.
I have a windows build and in taskmanager the memory usage just keep climbing.

I am totally lost at the moment. spend about 6 hours last
night trying to fix the problem and still haven't found to problem.

if anyone could point me in the right direction it would be greatly appreciated.

here is a link it the source code.

www.webpoint-servers.com/sdl/lad.rar

hope you can help a very tired nOOb

Thanks

Mac
 
Are you sure you are not doing something like overfilling an array? Often that causes what you are describing.

You might have defined something as posx[20]; then somehow gone way beyond the 20.
 
Hi craigix

Thanks for getting back to me

I don't think so. every time I access the vector that stores maze data I check the bounds.
plus if I leave the game running without moving the player or access accessing the maze vector
it still hangs. it's really strange

i.e.

if(CheckCell(PLAYER_Y,PLAYER_X+1))
{
if(MAZED[PLAYER_Y][PLAYER_X+1]!=1){
MAZED[PLAYER_Y][PLAYER_X] = 0;
SetPlayer(PLAYER_Y,PLAYER_X+1);
}
}

CheckCell function

bool CMaze::CheckCell(int y, int x)
{
if((y>=0 && y<HEIGHT) && (x>=0 && x<WIDTH))
{
return true;
}else{
return false;
}
}

Thanks again

Mac
 
well I found out what the problem was
I had mad a mess of the text drawing class.

thanks for the help tho craigix
 
Don't call SDL_FreeSurface() on the screen created by SetVideoMode (which is what I'm assuming you're doing since you're also passing it to Flip().
FreeSurface() is only there for surfaces you explicitly create - using it on the SetVideoMode screen does nothing (it checks to prevent anything bad happening).
If you want to clear the surface call SDL_FillRect(game->screen, NULL, 0); The NULL equates to the whole surface, and the 0 to the colour to fill with.
 
Back
Top