SDL Problem

Hello everyone, I'm currently recreating the first level or mario using the SDL library for practice.

Here's my project (Code::Blocks file)
http://www.sendspace.com/file/bi9v06

So far I just have the background and mario loaded to the screen, and you can move mario around but there's no animation yet.

The problem I'm having is that after around a minute of moving around the background image disappears (but mario doesn't) and I have no idea why.

Can someone help me please?

Thanks.
You are loading the images each time you use them but you never free them. The program will use more and more memory and what probably happens is that it fails to load the background because there is no free memory to store it in. That's why the background disappears. Mario is much smaller so it's easier to find memory to store it in so you can keep loading him for a while longer.

Just load the images before you use them and reuse them throughout the game. When you are done using them you can free them by using SDL_FreeSurface.
Last edited on
Thanks, it works now.
Topic archived. No new replies allowed.