Problens with free surface

Hi,

I have one game with photo albun with games screenshots. Now i am
develop one screen to display shots captured by game.
It will display one screenshot by time, I think the best way is using
one surface for all of them, and free it after use. But its not
working on.
I am also using SDL_Resize lib for resize images before display it.

Look a little bit from my code:

void Ltr_DispararTelaLogScreenShots()
{
SDL_Surface* sfcResized = NULL; // Surface for all images
display. BUG for freesurface.
SDL_Rect recResized = {80,25,640,480}; // Store location of image at album.
SDL_Event evnt; // Event managerment.
long current = 0;
char screenShotFile[200+1];

// Get last valid file from path.
for (current=1;; current++)
{
	FILE *fp = NULL;
	memset(screenShotFile, 0, sizeof(screenShotFile));
	sprintf(screenShotFile, "screenshots/shot%06d.png", current);

	fp = fopen(screenShotFile, "r");

	// If cant open, we found last file.
	if (!fp)
		break;

	fclose(fp);
}
--current;

// If we have a valid last file, display it on screen.
if (current>0)
{	
	memset(screenShotFile, 0, sizeof(screenShotFile));
	sprintf(screenShotFile, "screenshots/shot%06d.png", screenShotFile);

	LoadImg(&sfcResized, screenShotFile);

	SDL_ResizeXY(sfcResized, 640, 480, 2);	
	SDL_BlitSurface(sfcResized, NULL, sfcTela, &recResized);
	SDL_UpdateRect(sfcTela, 0, 0, TELA_W, TELA_H);
}

while (current>0)
{
	SDL_Delay(50);

	// We only change the surface if has key press to change it.
	if( !SDL_PollEvent(&evnt) || (evnt.type != SDL_KEYDOWN) )
		continue;

	switch (evnt.key.keysym.sym)
	{
		FILE *fp = NULL;

		case SDLK_a:
			if (current > 1)
				current--;
		break;

		case SDLK_s:
			memset(screenShotFile, 0, sizeof(screenShotFile));
			sprintf(screenShotFile, "screenshots/shot%06d.png", current+1);

			fp = fopen(screenShotFile, "r");

			// If its a valid file, we can use it.
			if (fp)
			{
				current++;
				fclose(fp);
			}
		break;

		case SDLK_ESCAPE:
			current = -1;
		break;
	}

	if (current < 1)
		break;
	
	SDL_FreeSurface(sfcResized);

	memset(screenShotFile, 0, sizeof(screenShotFile));
	sprintf(screenShotFile, "screenshots/shot%06d.png", current);

	LoadImg(&sfcResized, screenShotFile);

	SDL_ResizeXY(sfcResized, 640, 480, 2);
	SDL_BlitSurface(sfcResized, NULL, sfcTela, &recResized);	
	SDL_UpdateRect(sfcTela, 0, 0, TELA_W, TELA_H);
}

}

When i call SDL_FreeSurface(sfcResized); some times it broken beause
dont have a valid surface. Anyone can help me to find why I dont have
a valid surface?–
R?ben L?cio Reis

Game Developer
Linux user #433535

Hi.

Looking at the source of SDL_Resize, it Frees the image that was passed to it.
As such it would seem that you are trying to double-free the pointer.

I think if you change code that uses SDL_ResizeXY from code like:
SDL_ResizeXY(sfcResized, 640, 480, 2);
SDL_BlitSurface(sfcResized, NULL, sfcTela, &recResized);
SDL_UpdateRect(sfcTela, 0, 0, TELA_W, TELA_H);
to:
sfcResized = SDL_ResizeXY(sfcResized, 640, 480, 2);
SDL_BlitSurface(sfcResized, NULL, sfcTela, &recResized);
SDL_UpdateRect(sfcTela, 0, 0, TELA_W, TELA_H);

It might work .However, I do not have a compiler here to test this on…

HTH.On 12/07/07, R?ben L?cio wrote:

Hi,

I have one game with photo albun with games screenshots. Now i am
develop one screen to display shots captured by game.
It will display one screenshot by time, I think the best way is using
one surface for all of them, and free it after use. But its not
working on.

R?ben L?cio Reis

SDL_Surface* sfcResized = NULL; // Surface for all images
display. BUG for freesurface.
SDL_Rect recResized = {80,25,640,480}; // Store location of image at
album. SDL_Event evnt; // Event managerment.
long current = 0;
char screenShotFile[200+1];

// Get last valid file from path.
for (current=1;; current++)
{
FILE *fp = NULL;
memset(screenShotFile, 0, sizeof(screenShotFile));
sprintf(screenShotFile, “screenshots/shot%06d.png”, current);

  fp = fopen(screenShotFile, "r");

  // If cant open, we found last file.
  if (!fp)
  	break;

  fclose(fp);

}
–current;

Just one note: you could use stat() to find out if the file exists and is a
regular file, too. Further, two more notes on string handling:

  1. The memset() call is superfluous, sprintf() correctly terminates the
    string.
  2. Use snprintf() for safety. Even better, use a function
    char const* get_screenshot_path(unsigned index);
    that either formats the path into a static buffer or invokes exit() on error,
    because you are using the same code below again. :wink:

// If we have a valid last file, display it on screen.
if (current>0)
{
memset(screenShotFile, 0, sizeof(screenShotFile));
sprintf(screenShotFile, “screenshots/shot%06d.png”, screenShotFile);

  LoadImg(&sfcResized, screenShotFile);

  SDL_ResizeXY(sfcResized, 640, 480, 2);

I can’t find this function anywhere in SDL, are you using the external
SDL_Resize lib? If so, this function supposedly returns a new surface(!)
which obviously needs to be used from then on and also freed. Digging into
said library, it gets even worse: it seems like the input surface is
destroyed(WTF?) so you must not use sfcResized after calling this function.
This library is so broken, words fail me. Well, after all the behaviour is
documented (read the headers!) but still.

David, in case you’re reading this, consider changing this please! Also, you
notice that you couldn’t get this to compile as C code under VS2005. This is
probably due to the fact that your code is not valid C89 code because it
mixes declarations and code is some functions. If you supply the error
message, I’m sure we can work out the reason.

When i call SDL_FreeSurface(sfcResized); some times it broken beause
dont have a valid surface. Anyone can help me to find why I dont have
a valid surface?

No surprise, see above. If stretching is all you need, there used to be a
function in SDL (SDL_StretchBlit or somesuch) which was half-official but at
least does the job without any surprises like SDL_ResizeXY, I’d use that
until the SDL_Resize lib has been changed. Alternatively, you could fix it
yourself or work around it.

BTW: your code mostly looks fine, but it completely lacks checking of
returnvalues and errorcodes, so it’s possible that something in between is
failing without you even noticing. Don’t start adding error handling when
code begins to fail!

UliOn Thursday 12 July 2007 15:36:54 R?ben L?cio wrote:

snip

I can’t find this function anywhere in SDL, are you using the external
SDL_Resize lib? If so, this function supposedly returns a new surface(!)
which obviously needs to be used from then on and also freed. Digging into
said library, it gets even worse: it seems like the input surface is
destroyed(WTF?) so you must not use sfcResized after calling this
function.
This library is so broken, words fail me. Well, after all the behaviour is
documented (read the headers!) but still.

Hi Ulrich,
I don’t understand why you say it is “so broken” that words fail you! It
works great for me and I know other people have used it just fine as well…
Ruben was using it incorrectly, no wonder he had problems. (I had trouble
using SDL at first… it wasn’t because SDL was broken - I had to learn how
to use it!)
Of course it returns a new surface - if you want a resized surface, it can’t
be just the old one! Is there something “broken” about returning an
SDL_Surface *?
As to why the input surface is destroyed, this is for ease of
implementation, as one can throw a SDL_LoadBMP or IMG_Load or TTF_Render
(something that gives you an SDL_Surface *) directly into the function call,
and resize it and free it all at once.
e.g.
SDL_Surface * mytext = SDL_ResizeXY(TTF_RenderText_Blended(myfont,“SDL is
great”,mycolor), 150, 20, 7);

The only “broken-ness” I see as I look at it, is that I do not have the
library check to make sure it is passed a valid Surface *… That is
super-easy to fix and I’ll update that right away…

The errors I get when compiling as C all seem to be related to not
forward-declaring variables… I’ll try to clean those up and get back to
you if I get some more errors - Thanks for the offer to help!

-Dave

David, in case you’re reading this, consider changing this please! Also,
you
notice that you couldn’t get this to compile as C code under VS2005. This
is
probably due to the fact that your code is not valid C89 code because it
mixes declarations and code is some functions. If you supply the error
message, I’m sure we can work out the reason.

When i call SDL_FreeSurface(sfcResized); some times it broken beause
dont have a valid surface. Anyone can help me to find why I dont have
a valid surface?

No surprise, see above. If stretching is all you need, there used to be a
function in SDL (SDL_StretchBlit or somesuch) which was half-official but
at
least does the job without any surprises like SDL_ResizeXY, I’d use that
until the SDL_Resize lib has been changed. Alternatively, you could fix it
yourself or work around it.

BTW: your code mostly looks fine, but it completely lacks checking of
returnvalues and errorcodes, so it’s possible that something in between is
failing without you even noticing. Don’t start adding error handling when
code begins to fail!

Uli


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

----- Original Message -----
From: doomster@knuut.de (Ulrich Eckhardt)
To:
Sent: Friday, July 13, 2007 5:04 AM
Subject: Re: [SDL] Problens with free surface

I’m just replying to my own message to say that after cleaning up the
forward variable declarations, it the SDL_Resize library compiles just fine
as C or C++ in VS2005. I also included a brief check to make sure a valid
Surface * is passed into each Resize function, so it will return NULL
instead of crashing if you pass it a NULL surface by accident. I have
updated the entry on libsdl.org and loaded the updated library onto my
webspace, so if anyone wants to try it out, you should download the newest
version.
Ulrich, I’m still interested in your suggestions as to improvements/fixes.
-Dave OlsenOn 7/14/07, David Olsen <@David_Olsen> wrote:

----- Original Message -----
From: “Ulrich Eckhardt”
To:
Sent: Friday, July 13, 2007 5:04 AM
Subject: Re: [SDL] Problens with free surface

snip

I can’t find this function anywhere in SDL, are you using the external
SDL_Resize lib? If so, this function supposedly returns a new surface(!)
which obviously needs to be used from then on and also freed. Digging
into
said library, it gets even worse: it seems like the input surface is
destroyed(WTF?) so you must not use sfcResized after calling this
function.
This library is so broken, words fail me. Well, after all the behaviour
is
documented (read the headers!) but still.

Hi Ulrich,
I don’t understand why you say it is “so broken” that words fail you! It
works great for me and I know other people have used it just fine as
well…
Ruben was using it incorrectly, no wonder he had problems. (I had trouble
using SDL at first… it wasn’t because SDL was broken - I had to learn
how
to use it!)
Of course it returns a new surface - if you want a resized surface, it
can’t
be just the old one! Is there something “broken” about returning an
SDL_Surface *?
As to why the input surface is destroyed, this is for ease of
implementation, as one can throw a SDL_LoadBMP or IMG_Load or TTF_Render
(something that gives you an SDL_Surface *) directly into the function
call,
and resize it and free it all at once.
e.g.
SDL_Surface * mytext = SDL_ResizeXY(TTF_RenderText_Blended(myfont,“SDL is
great”,mycolor), 150, 20, 7);

The only “broken-ness” I see as I look at it, is that I do not have the
library check to make sure it is passed a valid Surface *… That is
super-easy to fix and I’ll update that right away…

The errors I get when compiling as C all seem to be related to not
forward-declaring variables… I’ll try to clean those up and get back to
you if I get some more errors - Thanks for the offer to help!

-Dave

David, in case you’re reading this, consider changing this please! Also,
you
notice that you couldn’t get this to compile as C code under VS2005.
This
is
probably due to the fact that your code is not valid C89 code because it
mixes declarations and code is some functions. If you supply the error
message, I’m sure we can work out the reason.

When i call SDL_FreeSurface(sfcResized); some times it broken beause
dont have a valid surface. Anyone can help me to find why I dont have
a valid surface?

No surprise, see above. If stretching is all you need, there used to be
a
function in SDL (SDL_StretchBlit or somesuch) which was half-official
but
at
least does the job without any surprises like SDL_ResizeXY, I’d use that
until the SDL_Resize lib has been changed. Alternatively, you could fix
it
yourself or work around it.

BTW: your code mostly looks fine, but it completely lacks checking of
returnvalues and errorcodes, so it’s possible that something in between
is
failing without you even noticing. Don’t start adding error handling
when
code begins to fail!

Uli


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

snip

I can’t find this function anywhere in SDL, are you using the
external

SDL_Resize lib? If so, this function supposedly returns a new
surface(!)

which obviously needs to be used from then on and also freed.
Digging into

said library, it gets even worse: it seems like the input surface
is

destroyed(WTF?) so you must not use sfcResized after calling this
function.
This library is so broken, words fail me. Well, after all the
behaviour is

documented (read the headers!) but still.

Hi Ulrich,
I don’t understand why you say it is “so broken” that words fail you!
It
works great for me and I know other people have used it just fine as
well…

Ruben was using it incorrectly, no wonder he had problems. (I had
trouble
using SDL at first… it wasn’t because SDL was broken - I had to
learn how
to use it!)
Of course it returns a new surface - if you want a resized surface,
it can’t
be just the old one! Is there something “broken” about returning an
SDL_Surface *?

I won’t claim expertise on this since I haven’t studied the source
code. But this relates to something that ran through my head when I was
looking at the SDL_ConvertSurface function. It too returns a new
surface. In my mind it would be beneficial to actually convert/resize a
surface and return a pointer that can be re-assigned to the pointer of
the surface being passed in the convert/resize function.

SDL_Surface *blah;
.
// do stuff with surface
.
blah = SDL_ConvertSurface (blah, … ;

where you pass the pointer to the surface to the function and return a
value that can be re-assigned to the same pointer. This would probably
require some internal freeing of the original surface rather than leave
it to the programmer to do some temporary trade outs. At the same time
the function would have to be safe enough to assign the converted
surface to a totally new surface pointer also.>>> On 7/14/2007 at 9:23 AM, “David Olsen” wrote:

----- Original Message -----
From: “Ulrich Eckhardt”
To:
Sent: Friday, July 13, 2007 5:04 AM
Subject: Re: [SDL] Problens with free surface


Lilith

[…]

I can’t find this function anywhere in SDL, are you using the external
SDL_Resize lib? If so, this function supposedly returns a new surface(!)
which obviously needs to be used from then on and also freed. Digging
into said library, it gets even worse: it seems like the input surface is
destroyed(WTF?) so you must not use sfcResized after calling this
function.
This library is so broken, words fail me. Well, after all the behaviour
is documented (read the headers!) but still.

Hi Ulrich,
I don’t understand why you say it is “so broken” that words fail you!

I’m sorry, those words were harsh and also due to the fact that up to that
point I hadn’t completely read the header/docs either. Please accept my
excuse.

Of course it returns a new surface - if you want a resized surface, it
can’t be just the old one! Is there something “broken” about returning an
SDL_Surface *?

There are two ways it could work, either if you supply a target surface, just
like SDL_StretchBlit() or the way you do it, i.e. returning a new surface.

As to why the input surface is destroyed, this is for ease of
implementation, as one can throw a SDL_LoadBMP or IMG_Load or TTF_Render
(something that gives you an SDL_Surface *) directly into the function
call, and resize it and free it all at once.
e.g.
SDL_Surface * mytext = SDL_ResizeXY(TTF_RenderText_Blended(myfont,“SDL is
great”,mycolor), 150, 20, 7);

This is the point I don’t agree with. I would assume that the function doesn’t
touch the input surface and I wouldn’t sacrifice it for this ease of use.

Thinking about it, I would prefer the SDL_StretchBlit interface, because it
allows me to compose and simultaneously resize images, i.e. it doesn’t have
the enforced allocation overhead. Creating the current behaviour from this
interface would be feasible without overhead then.

UliOn Saturday 14 July 2007 16:23:18 David Olsen wrote:

----- Original Message -----
From: “Ulrich Eckhardt” <@Ulrich_Eckhardt>

snip

I can’t find this function anywhere in SDL, are you using the external
SDL_Resize lib? If so, this function supposedly returns a new surface(!)
which obviously needs to be used from then on and also freed. Digging into
said library, it gets even worse: it seems like the input surface is
destroyed(WTF?) so you must not use sfcResized after calling this
function.
This library is so broken, words fail me. Well, after all the behaviour is
documented (read the headers!) but still.

Hi Ulrich,
I don’t understand why you say it is “so broken” that words fail you! It
works great for me and I know other people have used it just fine as well…
Ruben was using it incorrectly, no wonder he had problems. (I had trouble
using SDL at first… it wasn’t because SDL was broken - I had to learn how
to use it!)
Of course it returns a new surface - if you want a resized surface, it can’t
be just the old one! Is there something “broken” about returning an
SDL_Surface *?
As to why the input surface is destroyed, this is for ease of
implementation, as one can throw a SDL_LoadBMP or IMG_Load or TTF_Render
(something that gives you an SDL_Surface *) directly into the function call,
and resize it and free it all at once.
e.g.
SDL_Surface * mytext = SDL_ResizeXY(TTF_RenderText_Blended(myfont,“SDL is
great”,mycolor), 150, 20, 7);

SDL is not broken. It work as well. What dont work as well is lib
SDL_Resize. That is not a oficial sdl lib.

The only “broken-ness” I see as I look at it, is that I do not have the
library check to make sure it is passed a valid Surface *… That is
super-easy to fix and I’ll update that right away…

The errors I get when compiling as C all seem to be related to not
forward-declaring variables… I’ll try to clean those up and get back to
you if I get some more errors - Thanks for the offer to help!

Maybe that is my error. I was fix SDL_Resize for compile as C ANSI.On 7/14/07, David Olsen wrote:

----- Original Message -----
From: “Ulrich Eckhardt”
To:
Sent: Friday, July 13, 2007 5:04 AM
Subject: Re: [SDL] Problens with free surface

-Dave

David, in case you’re reading this, consider changing this please! Also,
you
notice that you couldn’t get this to compile as C code under VS2005. This
is
probably due to the fact that your code is not valid C89 code because it
mixes declarations and code is some functions. If you supply the error
message, I’m sure we can work out the reason.

When i call SDL_FreeSurface(sfcResized); some times it broken beause
dont have a valid surface. Anyone can help me to find why I dont have
a valid surface?

No surprise, see above. If stretching is all you need, there used to be a
function in SDL (SDL_StretchBlit or somesuch) which was half-official but
at
least does the job without any surprises like SDL_ResizeXY, I’d use that
until the SDL_Resize lib has been changed. Alternatively, you could fix it
yourself or work around it.

BTW: your code mostly looks fine, but it completely lacks checking of
returnvalues and errorcodes, so it’s possible that something in between is
failing without you even noticing. Don’t start adding error handling when
code begins to fail!

Uli


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


R?ben L?cio Reis

Game Developer
Linux user #433535

I’m just replying to my own message to say that after cleaning up the
forward variable declarations, it the SDL_Resize library compiles just fine
as C or C++ in VS2005. I also included a brief check to make sure a valid
Surface * is passed into each Resize function, so it will return NULL
instead of crashing if you pass it a NULL surface by accident. I have
updated the entry on libsdl.org and loaded the updated library onto my
webspace, so if anyone wants to try it out, you should download the newest
version.
Ulrich, I’m still interested in your suggestions as to improvements/fixes.

Thank you, i will test new version :)On 7/14/07, David Olsen wrote:

-Dave Olsen

On 7/14/07, David Olsen wrote:

----- Original Message -----
From: “Ulrich Eckhardt” < doomster at knuut.de>
To:
Sent: Friday, July 13, 2007 5:04 AM
Subject: Re: [SDL] Problens with free surface

snip

I can’t find this function anywhere in SDL, are you using the external
SDL_Resize lib? If so, this function supposedly returns a new surface(!)
which obviously needs to be used from then on and also freed. Digging
into

said library, it gets even worse: it seems like the input surface is
destroyed(WTF?) so you must not use sfcResized after calling this
function.
This library is so broken, words fail me. Well, after all the behaviour
is

documented (read the headers!) but still.

Hi Ulrich,
I don’t understand why you say it is “so broken” that words fail you! It
works great for me and I know other people have used it just fine as
well…
Ruben was using it incorrectly, no wonder he had problems. (I had trouble
using SDL at first… it wasn’t because SDL was broken - I had to learn
how
to use it!)
Of course it returns a new surface - if you want a resized surface, it
can’t
be just the old one! Is there something “broken” about returning an
SDL_Surface *?
As to why the input surface is destroyed, this is for ease of
implementation, as one can throw a SDL_LoadBMP or IMG_Load or TTF_Render
(something that gives you an SDL_Surface *) directly into the function
call,
and resize it and free it all at once.
e.g.
SDL_Surface * mytext =
SDL_ResizeXY(TTF_RenderText_Blended(myfont,“SDL is
great”,mycolor), 150, 20, 7);

The only “broken-ness” I see as I look at it, is that I do not have the
library check to make sure it is passed a valid Surface *… That is
super-easy to fix and I’ll update that right away…

The errors I get when compiling as C all seem to be related to not
forward-declaring variables… I’ll try to clean those up and get back to
you if I get some more errors - Thanks for the offer to help!

-Dave

David, in case you’re reading this, consider changing this please! Also,
you
notice that you couldn’t get this to compile as C code under VS2005.
This

is
probably due to the fact that your code is not valid C89 code because it
mixes declarations and code is some functions. If you supply the error
message, I’m sure we can work out the reason.

When i call SDL_FreeSurface(sfcResized); some times it broken beause
dont have a valid surface. Anyone can help me to find why I dont have
a valid surface?

No surprise, see above. If stretching is all you need, there used to be
a

function in SDL (SDL_StretchBlit or somesuch) which was half-official
but

at
least does the job without any surprises like SDL_ResizeXY, I’d use that
until the SDL_Resize lib has been changed. Alternatively, you could fix
it

yourself or work around it.

BTW: your code mostly looks fine, but it completely lacks checking of
returnvalues and errorcodes, so it’s possible that something in between
is

failing without you even noticing. Don’t start adding error handling
when

code begins to fail!

Uli


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


R?ben L?cio Reis

Game Developer
Linux user #433535

Ruben,
The library should now be valid C89… I would really appreciate you testing
out the latest version and letting me know whether it compiles and works
correctly in your program. (Don’t forget to use the surface * that is
returned by the function in the manner: surface =
SDL_ResizeXY(surface,x,y,filter); )
Thanks!
-David Olsen> ----- Original Message -----

From: rubenlr@gmail.com (Ruben Licio)
To: "A list for developers using the SDL library. (includes SDL-announce)"

Sent: Monday, July 16, 2007 8:01 AM
Subject: Re: [SDL] Problens with free surface

On 7/14/07, David Olsen <@David_Olsen> wrote:

I’m just replying to my own message to say that after cleaning up the
forward variable declarations, it the SDL_Resize library compiles just
fine
as C or C++ in VS2005. I also included a brief check to make sure a valid
Surface * is passed into each Resize function, so it will return NULL
instead of crashing if you pass it a NULL surface by accident. I have
updated the entry on libsdl.org and loaded the updated library onto my
webspace, so if anyone wants to try it out, you should download the
newest
version.
Ulrich, I’m still interested in your suggestions as to
improvements/fixes.

Thank you, i will test new version :slight_smile:

-Dave Olsen

On 7/14/07, David Olsen <@David_Olsen> wrote:

----- Original Message -----
From: “Ulrich Eckhardt” < doomster at knuut.de>
To:
Sent: Friday, July 13, 2007 5:04 AM
Subject: Re: [SDL] Problens with free surface

snip

I can’t find this function anywhere in SDL, are you using the
external
SDL_Resize lib? If so, this function supposedly returns a new
surface(!)
which obviously needs to be used from then on and also freed. Digging
into

said library, it gets even worse: it seems like the input surface is
destroyed(WTF?) so you must not use sfcResized after calling this
function.
This library is so broken, words fail me. Well, after all the
behaviour
is

documented (read the headers!) but still.

Hi Ulrich,
I don’t understand why you say it is “so broken” that words fail you!
It
works great for me and I know other people have used it just fine as
well…
Ruben was using it incorrectly, no wonder he had problems. (I had
trouble
using SDL at first… it wasn’t because SDL was broken - I had to learn
how
to use it!)
Of course it returns a new surface - if you want a resized surface, it
can’t
be just the old one! Is there something “broken” about returning an
SDL_Surface *?
As to why the input surface is destroyed, this is for ease of
implementation, as one can throw a SDL_LoadBMP or IMG_Load or
TTF_Render
(something that gives you an SDL_Surface *) directly into the function
call,
and resize it and free it all at once.
e.g.
SDL_Surface * mytext =
SDL_ResizeXY(TTF_RenderText_Blended(myfont,“SDL is
great”,mycolor), 150, 20, 7);

The only “broken-ness” I see as I look at it, is that I do not have the
library check to make sure it is passed a valid Surface *… That is
super-easy to fix and I’ll update that right away…

The errors I get when compiling as C all seem to be related to not
forward-declaring variables… I’ll try to clean those up and get back
to
you if I get some more errors - Thanks for the offer to help!

-Dave

David, in case you’re reading this, consider changing this please!
Also,
you
notice that you couldn’t get this to compile as C code under VS2005.
This

is
probably due to the fact that your code is not valid C89 code because
it
mixes declarations and code is some functions. If you supply the
error
message, I’m sure we can work out the reason.

When i call SDL_FreeSurface(sfcResized); some times it broken beause
dont have a valid surface. Anyone can help me to find why I dont
have
a valid surface?

No surprise, see above. If stretching is all you need, there used to
be
a

function in SDL (SDL_StretchBlit or somesuch) which was half-official
but

at
least does the job without any surprises like SDL_ResizeXY, I’d use
that
until the SDL_Resize lib has been changed. Alternatively, you could
fix
it

yourself or work around it.

BTW: your code mostly looks fine, but it completely lacks checking of
returnvalues and errorcodes, so it’s possible that something in
between
is

failing without you even noticing. Don’t start adding error handling
when

code begins to fail!

Uli


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


R?ben L?cio Reis

Game Developer
Linux user #433535


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Ruben,
The library should now be valid C89… I would really appreciate you testing
out the latest version and letting me know whether it compiles and works
correctly in your program. (Don’t forget to use the surface * that is
returned by the function in the manner: surface =
SDL_ResizeXY(surface,x,y,filter); )

David,

It works. With your new version, dont have problens at compile and running too.
I only have to change includes for my correct paths.

Congraturations!

I only will continue using SDL_Rotozoom because its much fast. But
your lib is going by a nice way.

See yah.On 7/16/07, David Olsen wrote:

Thanks!
-David Olsen

----- Original Message -----
From: “R?ben L?cio” <@Ruben_Licio>
To: "A list for developers using the SDL library. (includes SDL-announce)"

Sent: Monday, July 16, 2007 8:01 AM
Subject: Re: [SDL] Problens with free surface

On 7/14/07, David Olsen wrote:

I’m just replying to my own message to say that after cleaning up the
forward variable declarations, it the SDL_Resize library compiles just
fine
as C or C++ in VS2005. I also included a brief check to make sure a valid
Surface * is passed into each Resize function, so it will return NULL
instead of crashing if you pass it a NULL surface by accident. I have
updated the entry on libsdl.org and loaded the updated library onto my
webspace, so if anyone wants to try it out, you should download the
newest
version.
Ulrich, I’m still interested in your suggestions as to
improvements/fixes.

Thank you, i will test new version :slight_smile:

-Dave Olsen

On 7/14/07, David Olsen wrote:

----- Original Message -----
From: “Ulrich Eckhardt” < doomster at knuut.de>
To:
Sent: Friday, July 13, 2007 5:04 AM
Subject: Re: [SDL] Problens with free surface

snip

I can’t find this function anywhere in SDL, are you using the
external
SDL_Resize lib? If so, this function supposedly returns a new
surface(!)
which obviously needs to be used from then on and also freed. Digging
into

said library, it gets even worse: it seems like the input surface is
destroyed(WTF?) so you must not use sfcResized after calling this
function.
This library is so broken, words fail me. Well, after all the
behaviour
is

documented (read the headers!) but still.

Hi Ulrich,
I don’t understand why you say it is “so broken” that words fail you!
It
works great for me and I know other people have used it just fine as
well…
Ruben was using it incorrectly, no wonder he had problems. (I had
trouble
using SDL at first… it wasn’t because SDL was broken - I had to learn
how
to use it!)
Of course it returns a new surface - if you want a resized surface, it
can’t
be just the old one! Is there something “broken” about returning an
SDL_Surface *?
As to why the input surface is destroyed, this is for ease of
implementation, as one can throw a SDL_LoadBMP or IMG_Load or
TTF_Render
(something that gives you an SDL_Surface *) directly into the function
call,
and resize it and free it all at once.
e.g.
SDL_Surface * mytext =
SDL_ResizeXY(TTF_RenderText_Blended(myfont,“SDL is
great”,mycolor), 150, 20, 7);

The only “broken-ness” I see as I look at it, is that I do not have the
library check to make sure it is passed a valid Surface *… That is
super-easy to fix and I’ll update that right away…

The errors I get when compiling as C all seem to be related to not
forward-declaring variables… I’ll try to clean those up and get back
to
you if I get some more errors - Thanks for the offer to help!

-Dave

David, in case you’re reading this, consider changing this please!
Also,
you
notice that you couldn’t get this to compile as C code under VS2005.
This

is
probably due to the fact that your code is not valid C89 code because
it
mixes declarations and code is some functions. If you supply the
error
message, I’m sure we can work out the reason.

When i call SDL_FreeSurface(sfcResized); some times it broken beause
dont have a valid surface. Anyone can help me to find why I dont
have
a valid surface?

No surprise, see above. If stretching is all you need, there used to
be
a

function in SDL (SDL_StretchBlit or somesuch) which was half-official
but

at
least does the job without any surprises like SDL_ResizeXY, I’d use
that
until the SDL_Resize lib has been changed. Alternatively, you could
fix
it

yourself or work around it.

BTW: your code mostly looks fine, but it completely lacks checking of
returnvalues and errorcodes, so it’s possible that something in
between
is

failing without you even noticing. Don’t start adding error handling
when

code begins to fail!

Uli


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


R?ben L?cio Reis

Game Developer
Linux user #433535


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


R?ben L?cio Reis

Game Developer
Linux user #433535