Not sure but maybe a memory leak

First of all I am using Linux Fedora Core 3. I am writting a game
(poker for now) and have the cards and what-not animating. The issue is
that it appears to have a memory leak. I use ‘top’ and see that the
memory useage is increasing. Taking in account the system using
memory, I still see that the level is increasing. Below is a few line
of where I actually draw the graphic. I am asking if anyone sees my
issue or if there are known issues using SDL or IMG_Load?

SDL_Surface * surface_buffer[4];
/*
In another function the surface_buffers are created by using
SDL_SetVideoMode() for position 0 and the reset are created
using SDL_ConvertSurface() from the intial position.
*/

int Video_Draw_File(char* file_name, int x_pos, int y_pos, int width,
int heigth, int buffer){
SDL_Surface * image = NULL;
SDL_Rect dest, srcr;
Uint32 color_key;
//Load up the image.
dest.x=dest.y=dest.w=dest.h=0;
srcr.x=srcr.y=srcr.w=srcr.h=0;
image = IMG_Load((char*)file_name);
if(image == NULL){
//It may not be loaded so we need to check the cd rom.
// pngs/xxxx is not /mnt/cdrom/games/pngs/xxx
char temp_str[50];
sprintf(temp_str, “/mnt/cdrom/game/%s”, file_name);
image = IMG_Load((char*)temp_str);
if(image == NULL) return 1;
}
color_key = SDL_MapRGB(image->format, 255, 0, 255);
SDL_SetColorKey(image, SDL_SRCCOLORKEY | SDL_RLEACCEL ,color_key);
//Draw the image on the given buffer.
dest.x=x_pos; dest.y=y_pos;
srcr.x=0; srcr.y=0;
if(width==0){
dest.w=image->w;
srcr.w=image->w;
}else {
dest.w=width;
srcr.w=width;
}
if(heigth == 0) {
dest.h=image->h;
srcr.h=image->h;
}else {
dest.h=heigth;
srcr.h=heigth;
}
if((dest.w+dest.x <= SCREENWIDTH)){
SDL_BlitSurface((SDL_Surface*)image, &srcr,(SDL_Surface*)
surface_buffer[buffer], &dest);
} else {
SDL_BlitSurface((SDL_Surface*)image, NULL,(SDL_Surface*)
surface_buffer[buffer], &dest);
}
if(buffer==VO_BUFFER) { //The video screen (position 0 in the
surface_buffer array)
SDL_UpdateRect((SDL_Surface*)surface_buffer[buffer], dest.x,
dest.y, dest.w, dest.h);
}
SDL_FreeSurface(image); //Free up the graphics
image = 0;

//For development only
system(“cat /proc/meminfo > mem_file”);

return 0;
}

Thanks,
Walt

I have narrowed it down a bit more. I have found that using PNG
graphics seem to be an issue. I changed some of them to BMP to use the
SDL_LoadBMP to see if it might be the load_IMG() call. This dosen’t
have the memory creap. I then used the load_IMG() with the BMP file.
This seemed to also work with little issue. This might not be the place
but has anyone heard of issues using PNG’s? Can anyone recommend a
format that can use the transparencies (alpha channel). I have tried
TGA’s and they seem to have less of an issue but it still is creaping.
Unfortunatly, BMP cannot (I know you can declare a transparent color),
but I would like to use partial transparencies.

Thanks in advance,
Walt

walt wrote:> First of all I am using Linux Fedora Core 3. I am writting a game

(poker for now) and have the cards and what-not animating. The issue
is that it appears to have a memory leak. I use ‘top’ and see that
the memory useage is increasing. Taking in account the system using
memory, I still see that the level is increasing. Below is a few
line of where I actually draw the graphic. I am asking if anyone sees
my issue or if there are known issues using SDL or IMG_Load?

SDL_Surface * surface_buffer[4];
/*
In another function the surface_buffers are created by using
SDL_SetVideoMode() for position 0 and the reset are created
using SDL_ConvertSurface() from the intial position.
*/

int Video_Draw_File(char* file_name, int x_pos, int y_pos, int width,
int heigth, int buffer){
SDL_Surface * image = NULL;
SDL_Rect dest, srcr;
Uint32 color_key;
//Load up the image.
dest.x=dest.y=dest.w=dest.h=0;
srcr.x=srcr.y=srcr.w=srcr.h=0; image = IMG_Load((char*)file_name);
if(image == NULL){
//It may not be loaded so we need to check the cd rom.
// pngs/xxxx is not /mnt/cdrom/games/pngs/xxx
char temp_str[50];
sprintf(temp_str, “/mnt/cdrom/game/%s”, file_name);
image = IMG_Load((char*)temp_str);
if(image == NULL) return 1;
}
color_key = SDL_MapRGB(image->format, 255, 0, 255);
SDL_SetColorKey(image, SDL_SRCCOLORKEY | SDL_RLEACCEL ,color_key);
//Draw the image on the given buffer.
dest.x=x_pos; dest.y=y_pos;
srcr.x=0; srcr.y=0;
if(width==0){
dest.w=image->w;
srcr.w=image->w;
}else {
dest.w=width;
srcr.w=width;
}
if(heigth == 0) {
dest.h=image->h;
srcr.h=image->h;
}else {
dest.h=heigth;
srcr.h=heigth;
} if((dest.w+dest.x <= SCREENWIDTH)){
SDL_BlitSurface((SDL_Surface*)image, &srcr,(SDL_Surface*)
surface_buffer[buffer], &dest);
} else {
SDL_BlitSurface((SDL_Surface*)image, NULL,(SDL_Surface*)
surface_buffer[buffer], &dest);
}
if(buffer==VO_BUFFER) { //The video screen (position 0 in the
surface_buffer array)
SDL_UpdateRect((SDL_Surface*)surface_buffer[buffer], dest.x,
dest.y, dest.w, dest.h);
}
SDL_FreeSurface(image); //Free up the graphics
image = 0;

//For development only
system(“cat /proc/meminfo > mem_file”);
return 0;
}

Thanks,
Walt


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

Can anyone recommend a format that can use the transparencies (alpha channel). […]
Unfortunatly, BMP cannot (I know you can declare a transparent color),
but I would like to use partial transparencies.

You can, in fact, use BMPs. I split my 24 bit PNGs into a 8 bit BMP
colormap (or JPEG, depending on the case) and a 4 bit BMP alpha channel
and save them without RLE compression. They are LZW compressed by the
installer maker anyway. Then, on read, you read both BMPs and combine
them into a new SDL_Surface.

It works great for us! Saves a lot of space (compared with 24 bit PNGs
with alpha), it’s better than 8 bit PNGs with alpha (because 8 bit PNGs
only support 1 bit alpha) and the load process is quite fast.

–Gabriel

Hey,

What SDL_image version are you using? If you’re still worried about PNG
leaking you could try building SDL_image with a newer version of libpng
linked against it.

-TomT64

walt wrote:> I have narrowed it down a bit more. I have found that using PNG

graphics seem to be an issue. I changed some of them to BMP to use
the SDL_LoadBMP to see if it might be the load_IMG() call. This
dosen’t have the memory creap. I then used the load_IMG() with the
BMP file. This seemed to also work with little issue. This might not
be the place but has anyone heard of issues using PNG’s? Can anyone
recommend a format that can use the transparencies (alpha channel). I
have tried TGA’s and they seem to have less of an issue but it still
is creaping. Unfortunatly, BMP cannot (I know you can declare a
transparent color), but I would like to use partial transparencies.
Thanks in advance,
Walt

walt wrote:

First of all I am using Linux Fedora Core 3. I am writting a game
(poker for now) and have the cards and what-not animating. The issue
is that it appears to have a memory leak. I use ‘top’ and see that
the memory useage is increasing. Taking in account the system using
memory, I still see that the level is increasing. Below is a few
line of where I actually draw the graphic. I am asking if anyone
sees my issue or if there are known issues using SDL or IMG_Load?

SDL_Surface * surface_buffer[4];
/*
In another function the surface_buffers are created by using
SDL_SetVideoMode() for position 0 and the reset are created
using SDL_ConvertSurface() from the intial position.
*/

int Video_Draw_File(char* file_name, int x_pos, int y_pos, int
width, int heigth, int buffer){
SDL_Surface * image = NULL;
SDL_Rect dest, srcr;
Uint32 color_key;
//Load up the image.
dest.x=dest.y=dest.w=dest.h=0;
srcr.x=srcr.y=srcr.w=srcr.h=0; image = IMG_Load((char*)file_name);
if(image == NULL){
//It may not be loaded so we need to check the cd rom.
// pngs/xxxx is not /mnt/cdrom/games/pngs/xxx
char temp_str[50];
sprintf(temp_str, “/mnt/cdrom/game/%s”, file_name);
image = IMG_Load((char*)temp_str);
if(image == NULL) return 1;
}
color_key = SDL_MapRGB(image->format, 255, 0, 255);
SDL_SetColorKey(image, SDL_SRCCOLORKEY | SDL_RLEACCEL
,color_key); //Draw the image on the given buffer.
dest.x=x_pos; dest.y=y_pos;
srcr.x=0; srcr.y=0;
if(width==0){
dest.w=image->w;
srcr.w=image->w;
}else {
dest.w=width;
srcr.w=width;
}
if(heigth == 0) {
dest.h=image->h;
srcr.h=image->h;
}else {
dest.h=heigth;
srcr.h=heigth;
} if((dest.w+dest.x <= SCREENWIDTH)){
SDL_BlitSurface((SDL_Surface*)image, &srcr,(SDL_Surface*)
surface_buffer[buffer], &dest);
} else {
SDL_BlitSurface((SDL_Surface*)image, NULL,(SDL_Surface*)
surface_buffer[buffer], &dest);
}
if(buffer==VO_BUFFER) { //The video screen (position 0 in the
surface_buffer array)
SDL_UpdateRect((SDL_Surface*)surface_buffer[buffer], dest.x,
dest.y, dest.w, dest.h);
}
SDL_FreeSurface(image); //Free up the graphics
image = 0;

//For development only
system(“cat /proc/meminfo > mem_file”);
return 0;
}

Thanks,
Walt


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

Thanks for the information. This maybe all that I need to do. Do you by
chance have an example graphics that I can look at in an editor to see
this?

Walt.

Gabriel wrote:>>Can anyone recommend a format that can use the transparencies (alpha channel). […]

Unfortunatly, BMP cannot (I know you can declare a transparent color),
but I would like to use partial transparencies.

You can, in fact, use BMPs. I split my 24 bit PNGs into a 8 bit BMP
colormap (or JPEG, depending on the case) and a 4 bit BMP alpha channel
and save them without RLE compression. They are LZW compressed by the
installer maker anyway. Then, on read, you read both BMPs and combine
them into a new SDL_Surface.

It works great for us! Saves a lot of space (compared with 24 bit PNGs
with alpha), it’s better than 8 bit PNGs with alpha (because 8 bit PNGs
only support 1 bit alpha) and the load process is quite fast.

–Gabriel


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

Thanks for the information. This maybe all that I need to do. Do you by
chance have an example graphics that I can look at in an editor to see
this?

Not sure what you mean - any 24 bit png with alpha will do.

I am using SDL_image version 1.2.4. The libpng version is the latest
off of the web site (1.2.8). I downloaded both of these and rebuilt
both and still have the same issue. I did read on the png site that
they just fixed a bug dealing with it crashing when stripping off the
transparency. Maybe this might be an issue. I am going back a couple
of versions to see if it existed there.

Walt.

TomT64 wrote:> Hey,

What SDL_image version are you using? If you’re still worried about
PNG leaking you could try building SDL_image with a newer version of
libpng linked against it.

-TomT64

walt wrote:

I have narrowed it down a bit more. I have found that using PNG
graphics seem to be an issue. I changed some of them to BMP to use
the SDL_LoadBMP to see if it might be the load_IMG() call. This
dosen’t have the memory creap. I then used the load_IMG() with the
BMP file. This seemed to also work with little issue. This might
not be the place but has anyone heard of issues using PNG’s? Can
anyone recommend a format that can use the transparencies (alpha
channel). I have tried TGA’s and they seem to have less of an issue
but it still is creaping. Unfortunatly, BMP cannot (I know you can
declare a transparent color), but I would like to use partial
transparencies.
Thanks in advance,
Walt

walt wrote:

First of all I am using Linux Fedora Core 3. I am writting a game
(poker for now) and have the cards and what-not animating. The
issue is that it appears to have a memory leak. I use ‘top’ and see
that the memory useage is increasing. Taking in account the system
using memory, I still see that the level is increasing. Below is a
few line of where I actually draw the graphic. I am asking if
anyone sees my issue or if there are known issues using SDL or
IMG_Load?

SDL_Surface * surface_buffer[4];
/*
In another function the surface_buffers are created by using
SDL_SetVideoMode() for position 0 and the reset are created
using SDL_ConvertSurface() from the intial position.
*/

int Video_Draw_File(char* file_name, int x_pos, int y_pos, int
width, int heigth, int buffer){
SDL_Surface * image = NULL;
SDL_Rect dest, srcr;
Uint32 color_key;
//Load up the image.
dest.x=dest.y=dest.w=dest.h=0;
srcr.x=srcr.y=srcr.w=srcr.h=0; image = IMG_Load((char*)file_name);
if(image == NULL){
//It may not be loaded so we need to check the cd rom.
// pngs/xxxx is not /mnt/cdrom/games/pngs/xxx
char temp_str[50];
sprintf(temp_str, “/mnt/cdrom/game/%s”, file_name);
image = IMG_Load((char*)temp_str);
if(image == NULL) return 1;
}
color_key = SDL_MapRGB(image->format, 255, 0, 255);
SDL_SetColorKey(image, SDL_SRCCOLORKEY | SDL_RLEACCEL
,color_key); //Draw the image on the given buffer.
dest.x=x_pos; dest.y=y_pos;
srcr.x=0; srcr.y=0;
if(width==0){
dest.w=image->w;
srcr.w=image->w;
}else {
dest.w=width;
srcr.w=width;
}
if(heigth == 0) {
dest.h=image->h;
srcr.h=image->h;
}else {
dest.h=heigth;
srcr.h=heigth;
} if((dest.w+dest.x <= SCREENWIDTH)){
SDL_BlitSurface((SDL_Surface*)image, &srcr,(SDL_Surface*)
surface_buffer[buffer], &dest);
} else {
SDL_BlitSurface((SDL_Surface*)image, NULL,(SDL_Surface*)
surface_buffer[buffer], &dest);
}
if(buffer==VO_BUFFER) { //The video screen (position 0 in the
surface_buffer array)
SDL_UpdateRect((SDL_Surface*)surface_buffer[buffer], dest.x,
dest.y, dest.w, dest.h);
}
SDL_FreeSurface(image); //Free up the graphics
image = 0;

//For development only
system(“cat /proc/meminfo > mem_file”);
return 0;
}

Thanks,
Walt


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


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

I understand the any png will do, what I was asking was about the bmp
files. I don’t see how to set/save the transparent files. It doesn’t
seem to want to let me save the graphic.

Walt

Gabriel wrote:>>Thanks for the information. This maybe all that I need to do. Do you by

chance have an example graphics that I can look at in an editor to see
this?

Not sure what you mean - any 24 bit png with alpha will do.


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

I understand the any png will do, what I was asking was about the bmp
files. I don’t see how to set/save the transparent files. It doesn’t
seem to want to let me save the graphic.

With Gimp, you might be able to decompose an image with alpha transparency
so that you get the non-transparent part (save as BMP and use literally)
and the alpha part (as a greyscale layer; save also as a BMP and use as
your alpha channel).

I’ve never done it, and haven’t ever played with Decompose->Alpha in Gimp,
but it might be worth checking out.

(And, obviously, for GIF-like transparency, where it’s not an alpha level,
but simply an on-off, you can save the BMP with a special color that you
use for your color key. 0xFF00FF (magenta(?)), for example)On Tue, Feb 08, 2005 at 09:45:18AM -0700, walt wrote:


-bill!
bill at newbreedsoftware.com “I’m anticipating an all-out tactical
http://newbreedsoftware.com/ dog-fight, followed by a light dinner.”

I understand the any png will do, what I was asking was about the bmp
files. I don’t see how to set/save the transparent files. It doesn’t
seem to want to let me save the graphic.

With Gimp, you might be able to decompose an image with alpha transparency
so that you get the non-transparent part (save as BMP and use literally)
and the alpha part (as a greyscale layer; save also as a BMP and use as
your alpha channel).

I replied him in private with some sample files, but I wanted to point
out that you can make some simple scripts using ImageMagick and/or
NetPBM to split the alpha and the colormap in a batch way. I have this
integrated with my art pipeline.