Sdl app is segfaulting (how to debug) and the parachute

(hope this isn’t offtopic)

My sdl program is segfaulting sometimes, when I either
spawn/kill/update bullets, but not everytime. (I know it’s
related to my bullets, but not exactly what part.)

Can a debugger show me the line and the data used when the
program crashes?

I’m using dev-c++ 4.9.8.0 and it has gdb as it’s debugger. If
you know how, or of any howto’s that help explain how to use a
debugger, (for win32 or *nix) that’d be helpfull.

Also, what happens when the SDL parachute is deployed(after a
segfault)? Do I end up with memory that is used up untill I
reboot (for win32) or does it clean my mess up?

thanks,
jake__________________________________
Do you Yahoo!?
Friends. Fun. Try the all-new Yahoo! Messenger.
http://messenger.yahoo.com/

(If you know one of the answers that’s fine, any help is
appreciated)

a) I found the function [ void Projectiles::draw(void) ] does
not complete(it does for a while, even if bullets are spawned,
but seemingly randomly wont work). Do you see anything that
could cause a segfault?

b)

Can a debugger show me the line and the data used when the
program crashes?

c)

Also, what happens when the SDL parachute is deployed(after a
segfault)? Do I end up with memory that is used up untill I
reboot (for win32) or does it clean my mess up?

Here’s my code

void Projectiles::draw(void)
{
vector::iterator iter=projectile_list.begin();
while(iter != projectile_list.end())
{
pixel_set(screen, (int)iter->x, (int)iter->y, COLOR_BLACK);
pixel_set(screen, (int)iter->x+1, (int)iter->y,
COLOR_BLACK);
pixel_set(screen, (int)iter->x, (int)iter->y+1,
COLOR_BLACK);
pixel_set(screen, (int)iter->x+1, (int)iter->y+1,
COLOR_BLACK);
iter++;
}
}

//color black was set right before the main loop starts:
COLOR_BLACK = SDL_MapRGB(screen->format, 0,0,0);

void pixel_set(SDL_Surface *surface, int x, int y, Uint32 pixel)
{
//I didn’t create this function, I’m pretty sure its from SDL
docs
int bpp = surface->format->BytesPerPixel;
Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x *
bpp;

switch(bpp) {
case 1:
*p = pixel;
break;

case 2:
  *(Uint16 *)p = pixel;
  break;
  
case 3:
  if(SDL_BYTEORDER == SDL_BIG_ENDIAN) {
    p[0] = (pixel >> 16) & 0xff;
    p[1] = (pixel >> 8) & 0xff;
    p[2] = pixel & 0xff;
  }
  else {
    p[0] = pixel & 0xff;
    p[1] = (pixel >> 8) & 0xff;
    p[2] = (pixel >> 16) & 0xff;
  }
  break;
case 4:
  *(Uint32 *)p = pixel;
  break;

}
}

struct Projectile
{
float x;
float y;
double rotation;
Vector velocity;
};

–jake__________________________________
Do you Yahoo!?
Friends. Fun. Try the all-new Yahoo! Messenger.

(If you know one of the answers that’s fine, any help is
appreciated)

a) I found the function [ void Projectiles::draw(void) ] does
not complete(it does for a while, even if bullets are spawned,
but seemingly randomly wont work). Do you see anything that
could cause a segfault?

You could easily be writing off the end of the screen surface. pixel_set()
assumes that your x and y coordinates are between (0, 0) and (width-1,
height-1) but you have no check for this. The iter->x+1 and iter->y+1
expressions look like good candidates for generating this kind of error.
Can’t tell from the code you sent.

b)

Can a debugger show me the line and the data used when the
program crashes?

Yes, if you include the SDL_NOPARACHUTE flag when you call SDL_Init().

c)

Also, what happens when the SDL parachute is deployed(after a
segfault)? Do I end up with memory that is used up untill I
reboot (for win32) or does it clean my mess up?

The OS should clean up the process for you, but DirectX on Windows 98 stopped
doing this properly (for me) for certain kinds of crashes a long time ago,
and started requiring a reboot. I don’t develop using Win98 any more,

cheers,
John.On Tuesday 08 June 2004 01:08, jake b wrote:

Here’s my code

void Projectiles::draw(void)
{
vector::iterator iter=projectile_list.begin();
while(iter != projectile_list.end())
{
pixel_set(screen, (int)iter->x, (int)iter->y, COLOR_BLACK);
pixel_set(screen, (int)iter->x+1, (int)iter->y,
COLOR_BLACK);
pixel_set(screen, (int)iter->x, (int)iter->y+1,
COLOR_BLACK);
pixel_set(screen, (int)iter->x+1, (int)iter->y+1,
COLOR_BLACK);
iter++;
}
}

//color black was set right before the main loop starts:
COLOR_BLACK = SDL_MapRGB(screen->format, 0,0,0);

void pixel_set(SDL_Surface *surface, int x, int y, Uint32 pixel)
{
//I didn’t create this function, I’m pretty sure its from SDL
docs
int bpp = surface->format->BytesPerPixel;
Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x *
bpp;

switch(bpp) {
case 1:
*p = pixel;
break;

case 2:
*(Uint16 *)p = pixel;
break;

case 3:
if(SDL_BYTEORDER == SDL_BIG_ENDIAN) {
p[0] = (pixel >> 16) & 0xff;
p[1] = (pixel >> 8) & 0xff;
p[2] = pixel & 0xff;
}
else {
p[0] = pixel & 0xff;
p[1] = (pixel >> 8) & 0xff;
p[2] = (pixel >> 16) & 0xff;
}
break;
case 4:
*(Uint32 *)p = pixel;
break;
}
}

struct Projectile
{
float x;
float y;
double rotation;
Vector velocity;
};

–jake


Do you Yahoo!?
Friends. Fun. Try the all-new Yahoo! Messenger.
http://messenger.yahoo.com/


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

You could easily be writing off the end of the screen surface.
pixel_set()
assumes that your x and y coordinates are between (0, 0) and
(width-1,
height-1) but you have no check for this. The iter->x+1 and
iter->y+1
expressions look like good candidates for generating this kind
of error.
Can’t tell from the code you sent.

Thanks, I made an error when checking if it was onscreen.__________________________________
Do you Yahoo!?
Friends. Fun. Try the all-new Yahoo! Messenger.