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?
- The memset() call is superfluous, sprintf() correctly terminates the
string.
- 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.
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