SDL_Quit segfaulting

What reason would there be for SDL_Quit to segfault. I have some fairly simple
bump mapping code that runs fine except when I quit, then I get a seg fault.
Running the program under gdb reveals this:

Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 1024 (LWP 5512)]
__strtol_internal (nptr=0x1 <Address 0x1 out of bounds>, endptr=0xbffff9ac,
base=-1073743436, group=134514970) at eval.c:36
36 eval.c: No such file or directory.
in eval.c
(gdb) bt
#0 __strtol_internal (nptr=0x1 <Address 0x1 out of bounds>,
endptr=0xbffff9ac, base=-1073743436, group=134514970) at eval.c:36
#1 0x4002217e in SDL_Quit () at SDL.c:212
#2 0x4013ce5e in __libc_start_main (main=0x8048f88 , argc=1,
ubp_av=0xbffff9ac, init=0x8048904 <_init>, fini=0x80495c0 <_fini>,
rtld_fini=0x4000d3c4 <_dl_fini>, stack_end=0xbffff99c)
at …/sysdeps/generic/libc-start.c:129

If I comment out the SDL_Quit, the program exits fine? I’m not doing anything
differently (that I can tell) from any of my other simply SDL programs but
this one bombs (so obviously something is different). Thanks!–
Ti Leggett
leggett at eecs.tulane.edu

Ti Leggett wrote:

What reason would there be for SDL_Quit to segfault.

A bug in your code or in SDL. Please reduce your program to the absolute
minimum that still reproduces the segfault and post it here

More often than not this is sufficient to make you find your bug, and if
SDL is to blame it makes our task easier

A bug in your code or in SDL. Please reduce your program to the absolute
minimum that still reproduces the segfault and post it here

More often than not this is sufficient to make you find your bug, and if
SDL is to blame it makes our task easier

Here ya go. This is as simple as it gets. ‘image.png’ is a 24-bit png
created in gimp. I’m running SDL-1.2.0 and SDL_image-1.2.0.

#include <iostream.h>
#include “SDL.h”
#include “SDL_image.h”

SDL_Surface *surface;

int main( )
{
int videoFlags;

if ( SDL_Init( SDL_INIT_VIDEO ) < 0 )
    return 1;

videoFlags  = SDL_DOUBLEBUF;
videoFlags |= SDL_HWPALETTE;
videoFlags |= SDL_HWSURFACE;
videoFlags |= SDL_HWACCEL;

surface = SDL_SetVideoMode( 320, 200, 24, videoFlags );

if ( !surface )
    return 1;

SDL_Surface *color_map = IMG_Load( "image.png" );

bool done = false;
while ( !done )
    {

        SDL_BlitSurface( color_map, NULL, surface, NULL );

        SDL_Flip( surface );

    SDL_Event event;
    while ( SDL_PollEvent( &event ) )
	{
	    switch ( event.type )
		{
		case SDL_QUIT:
		    done = true;
		    break;
		case SDL_KEYDOWN:
		    if ( event.key.keysym.sym == SDLK_ESCAPE )
			done = true;
		    break;
		}
	}
    }

SDL_FreeSurface( color_map );
SDL_FreeSurface( surface );

SDL_Quit( );
return 0;

}On Mon, 20 Aug 2001, Mattias Engdegard wrote:


Ti Leggett
leggett at eecs.tulane.edu

[…]
surface = SDL_SetVideoMode( 320, 200, 24, videoFlags );
SDL_FreeSurface( surface );
[…]
SDL_Quit( );
[…]

Don’t call SDL_FreeSurface() on the value returned from
SDL_SetVideoMode(). SDL_Quit() will clean this up for you.

–ryan.

I removed the FreeSurface on the surface set by SetVideoMode and it still seg
faults.On 2001.08.20 21:52 Ryan C. Gordon wrote:

[…]
surface = SDL_SetVideoMode( 320, 200, 24, videoFlags );
SDL_FreeSurface( surface );
[…]
SDL_Quit( );
[…]

Don’t call SDL_FreeSurface() on the value returned from
SDL_SetVideoMode(). SDL_Quit() will clean this up for you.


Ti Leggett
leggett at eecs.tulane.edu

I removed the FreeSurface on the surface set by SetVideoMode and it still seg
faults.

I just tried the code here (with and without FreeSurface), and it ran
fine. I’m using a slightly newer SDL and SDL_image than you are, though.

Can you email me the actual PNG you’re using?

–ryan.

Alrighty! So after removing SDL and then searching for other SDL things lying
in the corners, I found an old installation that I had tried to enable
profiling in. I don’t think it was causing the problem since it was in
/usr/local which isn’t even in my LD_PATH but who knows. I removed all the SDL
I could find and rebuilt SDL and SDL_image… and it works now.

Super-uber thanks to Ryan for his help!On 2001.08.21 00:27 Ryan C. Gordon wrote:

I removed the FreeSurface on the surface set by SetVideoMode and it still
seg
faults.

I just tried the code here (with and without FreeSurface), and it ran
fine. I’m using a slightly newer SDL and SDL_image than you are, though.

Can you email me the actual PNG you’re using?

–ryan.


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


Ti Leggett
leggett at eecs.tulane.edu