Bizarre segfault

Hey everybody… I’m getting a segmentation fault while doing what would
seem to be a basic arithmetic operation, and I’ve having a bitch of a
time trying to figure it out. Hopefully somebody can shed some light on
the problem.

I’m using SDL-1.2.2 with VisualC++ 6.0 Standard Edition on Windows 98. I
have DirectX 8.0a, and am using it with a SiS6326-based video card.

The offending code is below. The segmentation fault (and the
corresponding SDL parachute) occur between the output of “Entering
function” and “Before blit”. This would suggest that it bombs out while
modifying SDL_Rect position for some reason.

Any help would be appreciated. Thanks in advance!

#include <stdio.h>

#include “SDL.h”
#include “SDL_image.h”

#define WINSIZEX 700
#define WINSIZEY 500

SDL_Surface *screen = NULL;

void drawcard (SDL_Surface *card, int x, int y)
{
SDL_Rect position;

printf(“Entering function\n”);
position.x = x - (card->w / 2);
position.y = y - (card->h / 2);
position.w = card->w;
position.h = card->h;

printf(“Before blit\n”);
if (SDL_BlitSurface(card, NULL, screen, &position) < 0)
printf(“BlitSurface error: %s\n”, SDL_GetError());

printf(“Before update\n”);
SDL_UpdateRects(screen, 1, &position);
}

int main(int argc, char *argv[])
{
Uint8 video_bpp = 32;
Uint32 videoflags;
SDL_Surface *card;
SDL_Event event;
int done, mousex, mousey;

videoflags = SDL_SWSURFACE;

if (SDL_Init(SDL_INIT_VIDEO) < 0) {
fprintf(stderr, “Couldn’t initialize SDL: %s\n”,SDL_GetError());
exit(1);
}
atexit(SDL_Quit);

if ((screen = SDL_SetVideoMode(WINSIZEX, WINSIZEY, video_bpp,
videoflags)) == NULL ) {
fprintf(stderr, “Couldn’t set %dx%dx%d video mode: %s\n”, WINSIZEX,
WINSIZEY, video_bpp, SDL_GetError());
exit(2);
}

SDL_WM_SetCaption(“Blah”, NULL);

SDL_FillRect(screen, NULL, 0x338833);
SDL_UpdateRect(screen, 0, 0, 0, 0);

card = IMG_Load(“cardbase.gif”);

done = 0;
while (!done) {
while (SDL_PollEvent(&event)) {
switch (event.type) {
case SDL_KEYDOWN:
done = 1;
break;

case SDL_MOUSEBUTTONDOWN:
  if (SDL_GetMouseState(&mousex, &mousey) & SDL_BUTTON(1)) {
    drawcard(card, mousex, mousey);
  }
  break;

case SDL_QUIT:
      done = 1;
      break;
    default:
      break;
  }
}

}
return(0);
}

Nevermind. I just had a flash of insight. It would probably help if the
image I was trying to load was in the directory in which it was expected
to be. I’m going to go smack myself in the head now.

“Jason L. Cook” wrote:>

Hey everybody… I’m getting a segmentation fault while doing what would
seem to be a basic arithmetic operation, and I’ve having a bitch of a
time trying to figure it out. Hopefully somebody can shed some light on
the problem.

doh! I replied to the list before getting this mail :)On Mon, Sep 10, 2001 at 06:35:57PM -0600, Jason L. Cook wrote:

Nevermind. I just had a flash of insight. It would probably help if the
image I was trying to load was in the directory in which it was expected
to be. I’m going to go smack myself in the head now.

“Jason L. Cook” wrote:

Hey everybody… I’m getting a segmentation fault while doing what would
seem to be a basic arithmetic operation, and I’ve having a bitch of a
time trying to figure it out. Hopefully somebody can shed some light on
the problem.


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


Adam
@Adam_Feakin
j: superpeach at jabber.org
-------------- next part --------------
A non-text attachment was scrubbed…
Name: not available
Type: application/pgp-signature
Size: 240 bytes
Desc: not available
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20010910/a263a8a0/attachment.pgp

This mailing list is for specific issues relating to SDL.

Please do not send general programming questions or requests for help.
If you want general programming or debugging help, use another forum,
or get on the SDL IRC channel: irc.openprojects.net, channel #SDL

Thanks,
-Sam Lantinga, Software Engineer, Blizzard Entertainment

You dont check if card == NULL after IMG_Load, are you sure that cardbase.gif
exists/SDL_image has gif support compiled.On Mon, Sep 10, 2001 at 06:29:23PM -0600, Jason L. Cook wrote:

SDL_FillRect(screen, NULL, 0x338833);
SDL_UpdateRect(screen, 0, 0, 0, 0);

card = IMG_Load(“cardbase.gif”);

done = 0;
while (!done) {
while (SDL_PollEvent(&event)) {


Adam
@Adam_Feakin
j: superpeach at jabber.org
-------------- next part --------------
A non-text attachment was scrubbed…
Name: not available
Type: application/pgp-signature
Size: 240 bytes
Desc: not available
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20010911/4b9a8a4d/attachment.pgp