Segfault when blitting background

Hi, I’m having a problem when blitting a background to my screen, when i
run gdb it says i get a seg fault in SDL_CalculateBlit(), I think it’s
probably something stupid I’ve done… but I’ve been looking at it for
too long and I can’t figure it out

I’m running on RedHat 9 with SDL 1.2.5

Here’s what i do that i think might be useful

I have a function to make new surfaces for tiling:

SDL_Surface *CreateNewBlankSurface(int width, int height){
Uint32 rmask, gmask, bmask, amask;
SDL_Surface surf;
/
SDL interprets each pixel as a 32-bit number, so our masks must
depend
on the endianness (byte order) of the machine */

#if SDL_BYTEORDER == SDL_BIG_ENDIAN
rmask = 0xff0000;
gmask = 0x00ff00;
bmask = 0x0000ff;
amask = 0x000000;
#else
rmask = 0x0000ff;
gmask = 0x00ff00;
bmask = 0xff0000;
amask = 0x000000;
#endif
surf = SDL_CreateRGBSurface(SDL_HWSURFACE, width, height, 0, rmask,
gmask, bmask, amask);
if(surf == NULL) {
cout << "CreateRGBSurface failed: " << SDL_GetError() << endl;
exit(1);
}
return surf;
SDL_FreeSurface(surf);
}

I set the video mode for my screen using:

screen = SDL_SetVideoMode(640, 480, 0, VideoSettings);

if(screen == NULL){
    cout << "Failed to set video mode!! " << SDL_GetError() << endl;
    exit(1);
}

i make the background surface:

background = CreateNewBlankSurface(screen->w, screen->h);

then i do tiling… then i draw to screen using:

bg.x = 0;
bg.y = 0;
bg.w = background->w;
bg.h = background->h;

SDL_BlitSurface(background, &bg, screen, &bg);

and i get the segfault in there

Please, don’t be to harsh if I’ve done something really stupid :slight_smile:

Sorry about this, but I’ve gone back to an earlier save and started
again and don’t get this error anymore. I would still like to know why i
got that error, but i guess it’s just kind of if you feel like wasting
some time :slight_smile:
Thanks
eugeneOn Wed, 2003-05-21 at 19:16, Eugene Marcotte wrote:

Hi, I’m having a problem when blitting a background to my screen, when i
run gdb it says i get a seg fault in SDL_CalculateBlit(), I think it’s
probably something stupid I’ve done… but I’ve been looking at it for
too long and I can’t figure it out

I’m running on RedHat 9 with SDL 1.2.5

Here’s what i do that i think might be useful

I have a function to make new surfaces for tiling:

SDL_Surface *CreateNewBlankSurface(int width, int height){
Uint32 rmask, gmask, bmask, amask;
SDL_Surface surf;
/
SDL interprets each pixel as a 32-bit number, so our masks must
depend
on the endianness (byte order) of the machine */

#if SDL_BYTEORDER == SDL_BIG_ENDIAN
rmask = 0xff0000;
gmask = 0x00ff00;
bmask = 0x0000ff;
amask = 0x000000;
#else
rmask = 0x0000ff;
gmask = 0x00ff00;
bmask = 0xff0000;
amask = 0x000000;
#endif
surf = SDL_CreateRGBSurface(SDL_HWSURFACE, width, height, 0, rmask,
gmask, bmask, amask);
if(surf == NULL) {
cout << "CreateRGBSurface failed: " << SDL_GetError() << endl;
exit(1);
}
return surf;
SDL_FreeSurface(surf);
}

I set the video mode for my screen using:

screen = SDL_SetVideoMode(640, 480, 0, VideoSettings);

if(screen == NULL){
    cout << "Failed to set video mode!! " << SDL_GetError() << endl;
    exit(1);
}

i make the background surface:

background = CreateNewBlankSurface(screen->w, screen->h);

then i do tiling… then i draw to screen using:

bg.x = 0;
bg.y = 0;
bg.w = background->w;
bg.h = background->h;

SDL_BlitSurface(background, &bg, screen, &bg);

and i get the segfault in there

Please, don’t be to harsh if I’ve done something really stupid :slight_smile:


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

if(surf == NULL) {
cout << "CreateRGBSurface failed: " <<
SDL_GetError() << endl;
exit(1);
}
return surf;
SDL_FreeSurface(surf);
}---------------------

That can’t be right, can it? Attempting to free a
surface, or indeed do anything, after the function has
returned? Does your compiler not complain about
unreachable code?

Paul


Do you Yahoo!?
The New Yahoo! Search - Faster. Easier. Bingo.
http://search.yahoo.com

actually… it doesn’t complain… i use gcc 3.2 i believe (whatever the
redhat 9 default gcc is) and i use the -Wall flag and it doesn’t say
anything. I’ve used the function on other small programs i’ve written
and they seemed to work with it also… would that cause the problem i
was having?On Fri, 2003-05-23 at 03:36, Paul Smith wrote:

if(surf == NULL) {
    cout << "CreateRGBSurface failed: " <<

SDL_GetError() << endl;
exit(1);
}
return surf;
SDL_FreeSurface(surf);
}


That can’t be right, can it? Attempting to free a
surface, or indeed do anything, after the function has
returned? Does your compiler not complain about
unreachable code?

Paul


Do you Yahoo!?
The New Yahoo! Search - Faster. Easier. Bingo.
http://search.yahoo.com


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