[SDL] Problem with reusing array of surfaces.
John Popplewell
john at johnnypops.demon.co.uk
Fri May 9 14:59:01 PDT 2003
Hi,
just a few questions. I was just wondering what happens inside your
LoadIMG() function:
Do you make any calls to, say, SDL_DisplayFormat()?
Are you using hardware or software surfaces?
Assuming you call SDL_SetColorKey(), do you use SDL_RLEACCEL?
Posting a small, complete, example program that demonstrates the
problem with a link to, say, a pair of your images that can be used
with the above program, will likely result in getting your problem
solved.
Either you will solve it yourself in the process of making the small,
complete, example, or someone on this list will be interested enough to
try and reproduce the problem and then help solve it,
best of luck,
John.
----- Original Message -----
From: "Sweeney, Steven (FNB)" <SweeneS at fnb.co.uk>
To: <sdl at libsdl.org>
Sent: Friday, May 09, 2003 3:05 PM
Subject: RE: [SDL] Problem with reusing array of surfaces.
> I had the same problem... Here are somethings you may or not be doing.
>
> 1. Initialise each surface pointer to NULL when you first create it.
>
> 2. Remember to call SDL_FreeSurface() before loading in a new image.
> SDL_Surface is a pointer to a memory location, so loading in another image
> using that pointer will not automatically free the data it will just
switch
> the memory pointer leaving the original data floating around with no way
to
> track it.
>
> 3. Calling,
>
> if (image[0] == NULL)
>
> and image[0] was never set to NULL to begin with will / might cause seg
> faults.
>
> > -----Original Message-----
> > From: Hri [SMTP:hr_hristov at hotmail.com]
> > Sent: Friday, May 09, 2003 2:19 PM
> > To: sdl at libsdl.org
> > Subject: [SDL] Problem with reusing array of surfaces.
> >
> > Most of my programming experience in the last years was the easy way -
> > java, c# even pascal but recently I have wiped the dust from my old c++
> > books and started some small sdl projects. I have a problem with the
> > code below. It simply loads images. Because I was lazy I hardcoded
> > several image sets that are loaded when a key is pressed. images[] is a
> > global variable and it is reused. If I swap the image sets a few
> > times (about 20 on winxp with 256) the program exits. Paul Nettle's
> > memory manager does not detect any memory leaks and there but I have
> > noticed that while the programs runs there about 5-10Mb RAM that remain
> > free.
> > I have added calls to SDL_FreeSurface but there was no difference. I it
> > does not free the memory what else should be done?
> >
> > void LoadImageSet01()
> > {
> > // the following loop doesn't help either
> > for ( int index = 0; index < 15; index ++ )
> > {
> > if ( images[ index ] != NULL )
> > SDL_FreeSurface( images[ index ] );
> > }
> > // Set transparent key color to blue (255)
> > ColorRGB transparent;
> > transparent.r = 0;
> > transparent.g = 0;
> > transparent.b = 255;
> >
> > // Load images
> > images[ 0 ] = LoadIMG( IMAGE0101, transparent );
> > images[ 1 ] = LoadIMG( IMAGE0102, transparent );
> > images[ 2 ] = LoadIMG( IMAGE0103, transparent );
> > images[ 3 ] = LoadIMG( IMAGE0104, transparent );
> > images[ 4 ] = LoadIMG( IMAGE0105, transparent );
> > images[ 5 ] = LoadIMG( IMAGE0106, transparent );
> > images[ 6 ] = LoadIMG( IMAGE0107, transparent );
> > images[ 7 ] = LoadIMG( IMAGE0108, transparent );
> > images[ 8 ] = LoadIMG( IMAGE0109, transparent );
> > images[ 9 ] = LoadIMG( IMAGE0110, transparent );
> > images[ 10 ] = LoadIMG( IMAGE0111, transparent );
> > images[ 11 ] = LoadIMG( IMAGE0112, transparent );
> > images[ 12 ] = LoadIMG( IMAGE0113, transparent );
> > images[ 13 ] = LoadIMG( IMAGE0114, transparent );
> > images[ 14 ] = LoadIMG( IMAGE0115, transparent );
> > }
> >
> > Note: this program works under WinNT if I do not switch between the
> > image sets too many times but under Win98 if I run the program a second
> > time all transparent colors (I use color keying) are no more
> > transparent. I believe I do every initialization and clean up as it is
> > explained in the docs.
> >
> > Is there any example (source code) that loads and destroys lots of large
> > images (1024x768) dynamically uses transparency and works correctly.
> >
> > Z.
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> > _______________________________________________
> > SDL mailing list
> > SDL at libsdl.org
> > http://www.libsdl.org/mailman/listinfo/sdl
> >
> >
> > .sophos.3.68.05.08.
>
> _______________________________________________
> SDL mailing list
> SDL at libsdl.org
> http://www.libsdl.org/mailman/listinfo/sdl
More information about the SDL
mailing list