Hi again,
I now use the SDL_CreateRGBSurfaceFrom(…) and it works fine.
But my SDL_FreeSurface problem is still there.
The memory simply will not free.
The following code is the code to Load an image from a File.
I usually do not free the memory directly after I?ve loaded it, but
I thought this would be a nice test.
But the memory will not free !
I see no error in the following code.
// Allocate dynamic memory
char * buffer = new char[size];
// Fill the memory with RAW-Pixel-data
file.read(buffer,size);
// Free the allocated memory
delete [] buffer;
So I?d like to ask you, if anyone had problems like this before, or if anyone finds an error in this code
or whatever.
My Application is a Point’n’Click-Adventure - Engine an so I have to free the memory of the Background-Image
and the Objects’ Images when a Scene swaps.
But in my case the memory just increases. I?ve “pushed” the memory by manual scene-swapping to 50 MB,
but my Game should just use about 10MB, so I?ve got 40MB Memory-Trash which does not free.
So I hope you have any suggestions or hints or whatever,
but help !!!
Nils>On Wed, 2 Feb 2005 16:01:32 +0100, Nils Wogatzky <@Nils_Wogatzky> wrote:
Hi all,
I?ve got a little problem with SDL_FreeSurface()
The Problem is: it doesn’t free memory.
I often change the Background image of my game, and when I load a new one, I free the old one.
But the used memory of my application just increases.
I am trying to free the Surfaces like this:
//(Images is a selfmade assoziative array and the Surface is stored in it in a .)
Hint: watch out when using STL vectors – at least the implementation
for MSVC6 is buggy IIRC, and not thread safe. I found a memory
deallocation problem when using vector::insert() some months ago
(haven’t dared using STL since then )
if(Images.Get(BackgroundFilename) != NULL)
{
SDL_Surface * pSurface = Images.Get(BackgroundFilename);
SDL_FreeSurface(pSurface);
pSurface = NULL;
}
just for Info: I’m loading images like this.
pSurface = SDL_CreateRGBSurface(SDL_SWSURFACE,width,height,bpp,NULL,NULL,NULL,NULL);
char * buffer = new char[size];
file.read((char*)buffer,size);
SDL_LockSurface(pSurface);
memcpy((char*)s->pixels,buffer,size);
This is only correct if s->pitch == s->w, that is when the pixel data
of s is one fat array. It is probably true for SDL_SWSURFACE’s in
general, but it is still not the recommended way of copying memory to
a surface. Why not use the SDL_CreateRGBSurfaceFrom(…) API? Should
speed things up a bit too. But be careful – you have to explicitly
delete[] the s->pixels buffer after the SDL_FreeSurface() call later!
delete[] buffer;
SDL_UnlockSurface(pSurface);
thank you for your help,
Nils
SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl
SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl