Correction to test/testsprite.c

Here are the diff’s to get a more correct
test/testsprite.c.
(Make them bouncing at a correct place, considering the screen surface.)

Would somebody put that in the CVS tree ?

Jean-Pierre H. Dumas=============================================
*** testsprite.c.old Fri Jul 13 12:20:42 2001
— testsprite.c Wed Feb 06 15:36:56 2002


*** 18,23 ****
— 18,24 ----
SDL_Rect *positions;
SDL_Rect *velocities;
int sprites_visible;

  • Uint16 sprite_w, sprite_h;

    int LoadSprite(SDL_Surface *screen, char *file)
    {


*** 66,77 ****
position = &positions[i];
velocity = &velocities[i];
position->x += velocity->x;
! if ( (position->x < 0) || (position->x >= screen->w) ) {
velocity->x = -velocity->x;
position->x += velocity->x;
}
position->y += velocity->y;
! if ( (position->y < 0) || (position->y >= screen->h) ) {
velocity->y = -velocity->y;
position->y += velocity->y;
}
— 67,78 ----
position = &positions[i];
velocity = &velocities[i];
position->x += velocity->x;
! if ( (position->x < 0) || (position->x >= (screen->w - sprite_w)) ) {
velocity->x = -velocity->x;
position->x += velocity->x;
}
position->y += velocity->y;
! if ( (position->y < 0) || (position->y >= (screen->h - sprite_w)) ) {
velocity->y = -velocity->y;
position->y += velocity->y;
}


*** 209,218 ****
sprite_rects += numsprites;
velocities = sprite_rects;
sprite_rects += numsprites;
srand(time(NULL));
for ( i=0; i<numsprites; ++i ) {
! positions[i].x = rand()%screen->w;
! positions[i].y = rand()%screen->h;
positions[i].w = sprite->w;
positions[i].h = sprite->h;
velocities[i].x = 0;
— 210,221 ----
sprite_rects += numsprites;
velocities = sprite_rects;
sprite_rects += numsprites;

  • sprite_w = sprite->w;
  • sprite_h = sprite->h;
    srand(time(NULL));
    for ( i=0; i<numsprites; ++i ) {
    ! positions[i].x = rand()%(screen->w - sprite_w);
    ! positions[i].y = rand()%(screen->h - sprite_h);
    positions[i].w = sprite->w;
    positions[i].h = sprite->h;
    velocities[i].x = 0;

*** 285,289 ****
— 288,293 ----
printf("%2.2f frames per second\n",
((double)frames*1000)/(now-then));
}

  • SDL_Quit();
    return(0);
    }

“Jean-Pierre H. Dumas” <jeanpierre.dumas at freesbee.fr> wrote:

Here are the diff’s to get a more correct
test/testsprite.c.
(Make them bouncing at a correct place, considering the screen surface.)

Please send patches in unified diff formats so we can read them.
Also if you are going to fix testsprite, please do it properly. You want
to test clipped RLE blits in all directions. The whole program needs an
overhaul anyway.

  • SDL_Quit();

This isn’t needed, taken care of by atexit()

  • SDL_Quit();
    

This isn’t needed, taken care of by atexit()

atexit is problematic for other reasons though, and probably shouldn’t
be used in SDL example programs. :slight_smile:

BTW, I promise I’ll update the website and CVS soon! :slight_smile:

-Sam Lantinga, Software Engineer, Blizzard Entertainment

Sam Lantinga wrote:

atexit is problematic for other reasons though, and probably shouldn’t
be used in SDL example programs. :slight_smile:

specifically what other reasons were you thinking about in SDL context?

Heh, everyone seems to use atexit in SDL programs, example or not. What
problems have been found with it?On Wed, Feb 06, 2002 at 10:24:22AM -0800, Sam Lantinga wrote:

  • SDL_Quit();
    

This isn’t needed, taken care of by atexit()

atexit is problematic for other reasons though, and probably shouldn’t
be used in SDL example programs. :slight_smile:


Joseph Carter Do not write in this space

“my biggest problem with RH (and especially RH contrib packages) is that
they DON’T have anything like our policy. That’s one of the main reasons
why their packages are so crappy and broken. Debian has the teamwork
side of building a distribution down to a fine art.”

-------------- next part --------------
A non-text attachment was scrubbed…
Name: not available
Type: application/pgp-signature
Size: 273 bytes
Desc: not available
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20020207/e5e37190/attachment.pgp

It doesn’t work well with other cleanup code.

For example, if somebody registers an atexit function before the
atexit(SDL_Quit), and calls an SDL function from it, then the application
may crash in a way that is very hard to debug. Static C++ objects that
call SDL functions from ctors/dtors have this problem too (never use them!)

In general, if you rely on explicit ordering of application cleanup, you
should check and perform all steps yourself in your own cleanup function.

See ya,
-Sam Lantinga, Software Engineer, Blizzard Entertainment> On Wed, Feb 06, 2002 at 10:24:22AM -0800, Sam Lantinga wrote:

  • SDL_Quit();
    

This isn’t needed, taken care of by atexit()

atexit is problematic for other reasons though, and probably shouldn’t
be used in SDL example programs. :slight_smile:

Heh, everyone seems to use atexit in SDL programs, example or not. What
problems have been found with it?

Sam Lantinga wrote:

For example, if somebody registers an atexit function before the
atexit(SDL_Quit), and calls an SDL function from it, then the application
may crash in a way that is very hard to debug.

But since the order of atexit-registered functions calls is well-defined
this is not a fundamental problem. Registering an atexit function that
cannot be called immediately is always a bug.

In general, if you rely on explicit ordering of application cleanup, you
should check and perform all steps yourself in your own cleanup function.

I agree that is a saner way to do it in general

Good to know.

Generally I use one anyway because I may want to print out debugging info
for the crashes caught by the program (“impossible” cases, memory debug
stuff, etc) and because we’d like to be able to gracefully die from the
majority of crashes.

What I wish we could do is have SDL tell us when we have an ungraceful
crash in progress so that we can implement our own parachutes. The one
SDL has is sometimes not sufficient, and signal catching tends to have
different semantics on different OSes. I have not looked to see if
there’s anything OS-specific in the parachute code, but if it just calls
SDL_Quit, a new SDL_Init flag SDL_USER_PARACHUTE or something is on my
wishlist. Probably should be accompanied by a warning not to get too
fancy with it, since it’s being called when, eg, you just segfaulted.On Thu, Feb 07, 2002 at 09:51:03AM -0800, Sam Lantinga wrote:

  • SDL_Quit();
    

This isn’t needed, taken care of by atexit()

atexit is problematic for other reasons though, and probably shouldn’t
be used in SDL example programs. :slight_smile:

Heh, everyone seems to use atexit in SDL programs, example or not. What
problems have been found with it?

It doesn’t work well with other cleanup code.

For example, if somebody registers an atexit function before the
atexit(SDL_Quit), and calls an SDL function from it, then the application
may crash in a way that is very hard to debug. Static C++ objects that
call SDL functions from ctors/dtors have this problem too (never use them!)

In general, if you rely on explicit ordering of application cleanup, you
should check and perform all steps yourself in your own cleanup function.


Joseph Carter I swallowed your goldfish

Indifference will certainly be the downfall of mankind, but who cares?

-------------- next part --------------
A non-text attachment was scrubbed…
Name: not available
Type: application/pgp-signature
Size: 273 bytes
Desc: not available
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20020207/f1fe4639/attachment.pgp