SDL 1.3 SDL_FillRect() segfault

Hi, my code is segfaulting when I do a SDL_FillRect:

widget->surface = SDL_CreateRGBSurface( SDL_SWSURFACE, widget->rect.w,

widget->rect.h, 24, rmask, gmask, bmask, amask );
if( !(widget->surface) ) {
printf( “SDL_CreateRGBSurface() returned NULL (from %s): %s\n”,
widget->name, SDL_GetError() );
return;
}

SDL_Rect bar;

bar.x = 2; bar.y = (widget->rect.h/2)-2;
bar.w = widget->rect.w-4; bar.h = 2;
SDL_FillRect( widget->surface, (const SDL_Rect *)&bar, SDL_MapRGB(

widget->surface->format, 150, 150, 150 ) );
bar.x = 2; bar.y = (widget->rect.h/2);
bar.w = widget->rect.w-4; bar.h = 2;
SDL_FillRect( widget->surface, (const SDL_Rect *)&bar, SDL_MapRGB(
widget->surface->format, 100, 100, 100 ) );

bar.x = ( ( slider->value - slider->min ) / ( slider->max - slider->min

) ) * ( widget->rect.w - 4 ); bar.y = 0;
bar.w = 4; bar.h = widget->rect.h;
SDL_FillRect( widget->surface, (const SDL_Rect *)&bar, SDL_MapRGB(
widget->surface->format, 170, 170, 170 ) );
SDL_DrawRect( widget->surface, (const SDL_Rect *)&bar, SDL_MapRGB(
widget->surface->format, 255, 255, 255 ) );

gdb points to this code: SDL_fillrect.c:292

Did I do something wrong with my code, or is this an issue with SDL?

Thanks,
-Alex

Is it possible that widget->rect.w is either uninitialized or less than 4?
Try printing out the value of ‘bar’ before you do a SDL_FillRect. If it’s
crazy, that might do it. Also, does it really need to be cast into a const
SDL_Rect*?

Jonny DOn Wed, Jul 21, 2010 at 1:58 PM, Alex Barry <alex.barry at gmail.com> wrote:

Hi, my code is segfaulting when I do a SDL_FillRect:

widget->surface = SDL_CreateRGBSurface( SDL_SWSURFACE, widget->rect.w,

widget->rect.h, 24, rmask, gmask, bmask, amask );
if( !(widget->surface) ) {
printf( “SDL_CreateRGBSurface() returned NULL (from %s): %s\n”,
widget->name, SDL_GetError() );
return;
}

SDL_Rect bar;

bar.x = 2; bar.y = (widget->rect.h/2)-2;
bar.w = widget->rect.w-4; bar.h = 2;
SDL_FillRect( widget->surface, (const SDL_Rect *)&bar, SDL_MapRGB(

widget->surface->format, 150, 150, 150 ) );
bar.x = 2; bar.y = (widget->rect.h/2);
bar.w = widget->rect.w-4; bar.h = 2;
SDL_FillRect( widget->surface, (const SDL_Rect *)&bar, SDL_MapRGB(
widget->surface->format, 100, 100, 100 ) );

bar.x = ( ( slider->value - slider->min ) / ( slider->max - slider->min

) ) * ( widget->rect.w - 4 ); bar.y = 0;
bar.w = 4; bar.h = widget->rect.h;
SDL_FillRect( widget->surface, (const SDL_Rect *)&bar, SDL_MapRGB(
widget->surface->format, 170, 170, 170 ) );
SDL_DrawRect( widget->surface, (const SDL_Rect *)&bar, SDL_MapRGB(
widget->surface->format, 255, 255, 255 ) );

gdb points to this code: SDL_fillrect.c:292

Did I do something wrong with my code, or is this an issue with SDL?

Thanks,
-Alex


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

I did a recompile after being frustrated walking away for a little bit, and
it magically fixed itself shrug
I must have changed something…I dunno.

Thanks anyway,
-AlexOn Wed, Jul 21, 2010 at 4:52 PM, Jonathan Dearborn wrote:

Is it possible that widget->rect.w is either uninitialized or less than 4?
Try printing out the value of ‘bar’ before you do a SDL_FillRect. If it’s
crazy, that might do it. Also, does it really need to be cast into a const
SDL_Rect*?

Jonny D

On Wed, Jul 21, 2010 at 1:58 PM, Alex Barry <@Alex_Barry> wrote:

Hi, my code is segfaulting when I do a SDL_FillRect:

widget->surface = SDL_CreateRGBSurface( SDL_SWSURFACE, widget->rect.w,

widget->rect.h, 24, rmask, gmask, bmask, amask );
if( !(widget->surface) ) {
printf( “SDL_CreateRGBSurface() returned NULL (from %s): %s\n”,
widget->name, SDL_GetError() );
return;
}

SDL_Rect bar;

bar.x = 2; bar.y = (widget->rect.h/2)-2;
bar.w = widget->rect.w-4; bar.h = 2;
SDL_FillRect( widget->surface, (const SDL_Rect *)&bar, SDL_MapRGB(

widget->surface->format, 150, 150, 150 ) );
bar.x = 2; bar.y = (widget->rect.h/2);
bar.w = widget->rect.w-4; bar.h = 2;
SDL_FillRect( widget->surface, (const SDL_Rect *)&bar, SDL_MapRGB(
widget->surface->format, 100, 100, 100 ) );

bar.x = ( ( slider->value - slider->min ) / ( slider->max -

slider->min ) ) * ( widget->rect.w - 4 ); bar.y = 0;
bar.w = 4; bar.h = widget->rect.h;
SDL_FillRect( widget->surface, (const SDL_Rect *)&bar, SDL_MapRGB(
widget->surface->format, 170, 170, 170 ) );
SDL_DrawRect( widget->surface, (const SDL_Rect *)&bar, SDL_MapRGB(
widget->surface->format, 255, 255, 255 ) );

gdb points to this code: SDL_fillrect.c:292

Did I do something wrong with my code, or is this an issue with SDL?

Thanks,
-Alex


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org