Problens with free surface [RESOLVED]

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…

Hi Brian,

The problem was SDL_Resize. I test it with rotozoom (SDL_gfx) and it
works as well.
Some times SDL_Resize dont Resize image, i dont know what exact is the
problem, but it was not work as well with my code.
I am using your sugestion with SDL_Rotozoom now!

Thank you!On 7/12/07, Brian <brian.ripoff at gmail.com> wrote:

HTH.

On 12/07/07, R?ben L?cio <@Ruben_Licio> 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 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

Hi Ruben,
Did you try the advice Brian gave you(and that I gave you in an
email) to use the method: sfcResized = SDL_ResizeXY(sfcResized, 640,
480, 2); ?
If so, did it resolve the problem? If it still crashes after that, I’d
be very interested to try your project out on my computer, to see if I
can find the bug (after all, I’m the one responsible for the
SDL_Resize library!)
Also, back in the day when I was looking for something to resize
images(prior to assembling the SDL_Resize lib), I also tried rotozoom.
It’s easy to use, but you need to know that it uses somewhat
rudimentary scaling, and the quality of the final image will be
inferior to the Lanczos3 scaling in SDL_Resize. I’m not trying to push
my library on you, I just want you to know that when I made it,
quality of the resized image was my top concern. It’s not fast, but it
looks good…
Would you please mind letting me/us know if your code works with
the addition that Brian suggested? Thanks!
-Dave OlsenOn 7/12/07, R?ben L?cio wrote:

On 7/12/07, Brian <brian.ripoff at gmail.com> wrote:

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…

Hi Brian,

The problem was SDL_Resize. I test it with rotozoom (SDL_gfx) and it
works as well.
Some times SDL_Resize dont Resize image, i dont know what exact is the
problem, but it was not work as well with my code.
I am using your sugestion with SDL_Rotozoom now!

Thank you!

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 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_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:

Nice, i will find more about stat function. Is it ansi?

  1. The memset() call is superfluous, sprintf() correctly terminates the
    string.
  2. Use snprintf() for safety.

I will find more about snprinf too, if its ansi i can use it instead sprintf.

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:

Oh, yeah, but for now i cant use this. project rules…

  // 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.

LoadImg is our internal function for load one png to sdl surface, it
uses display format and its work as well, we use it since more then 1
year ago.
SDL_Resize is one lib found at libsdl.org/libraries.php and, it was
the problem. All code works as well when i comment SDL_Resize calls.
Now, i replace sdl resize by sdl rotozoom from sdl gfx. And its work as well.
Yes, SDL_Resize destroyed my surface sometimes, but not every time.

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!

thank so much, i will search for your recomends functions!!On 7/13/07, Ulrich Eckhardt wrote:

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


R?ben L?cio Reis

Game Developer
Linux user #433535

Hi Ruben,
Did you try the advice Brian gave you(and that I gave you in an
email) to use the method: sfcResized = SDL_ResizeXY(sfcResized, 640,
480, 2); ?

Yes, i was use it before use without sfcResized = …
The problem was inside SDL_ResizeXY, this lib dont work as well as i
was think it works.

If so, did it resolve the problem? If it still crashes after that, I’d
be very interested to try your project out on my computer, to see if I
can find the bug (after all, I’m the one responsible for the
SDL_Resize library!)

I was resovle problem replace SDL Resize lib for SDL Rotozoom.

After testing this two libs, my conclusion is SDL Resize has bugs and
its slower.
SDL Rotozoom is much fast, and for now, i dont see any problem with it.

Thank you for help!

see yahOn 7/12/07, David Olsen wrote:

Also, back in the day when I was looking for something to resize

images(prior to assembling the SDL_Resize lib), I also tried rotozoom.
It’s easy to use, but you need to know that it uses somewhat
rudimentary scaling, and the quality of the final image will be
inferior to the Lanczos3 scaling in SDL_Resize. I’m not trying to push
my library on you, I just want you to know that when I made it,
quality of the resized image was my top concern. It’s not fast, but it
looks good…
Would you please mind letting me/us know if your code works with
the addition that Brian suggested? Thanks!
-Dave Olsen

On 7/12/07, R?ben L?cio <@Ruben_Licio> wrote:

On 7/12/07, Brian <brian.ripoff at gmail.com> wrote:

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…

Hi Brian,

The problem was SDL_Resize. I test it with rotozoom (SDL_gfx) and it
works as well.
Some times SDL_Resize dont Resize image, i dont know what exact is the
problem, but it was not work as well with my code.
I am using your sugestion with SDL_Rotozoom now!

Thank you!

HTH.

On 12/07/07, R?ben L?cio <@Ruben_Licio> 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 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