SDL Crashes on Exit

I have this in a separate thread:

SDL_Event event;

bool QuitSDL = false;

while(SDL_WaitEvent(&event))
{
    Display();
    QuitSDL = HandleEvents(event);

    if(QuitSDL)
    {
        break;
    }
}

SDL_Quit();

HandleEvents() returns true if the user pressed ESC or if they closed the
window.

When I do either of these events, the program segfaults. Anyone know why
this would be?

Thanks,

David

I have this in a separate thread:

SDL_Event event;

bool QuitSDL = false;

while(SDL_WaitEvent(&event))
{
    Display();
    QuitSDL = HandleEvents(event);

    if(QuitSDL)
    {
        break;
    }
}

SDL_Quit();

HandleEvents() returns true if the user pressed ESC or if they
closed the window.

When I do either of these events, the program segfaults. Anyone know
why this would be?

As far as I know, you cannot have SDL_WaitEvent in a different thread,
it has to be in the main thread.

Probably SDL_Quit can also not be in another thread.Am 01.04.2009 um 22:02 schrieb David Doria:

You can put stuff in a different thread as long as EVERYTHING for opengl is
in that thread. My application is working properly, it just crashes when I
exit.

Thanks,

DavidOn Wed, Apr 1, 2009 at 4:08 PM, Albert Zeyer <albert.zeyer at rwth-aachen.de>wrote:

Am 01.04.2009 um 22:02 schrieb David Doria:

I have this in a separate thread:

SDL_Event event;

bool QuitSDL = false;

while(SDL_WaitEvent(&event))
{
Display();
QuitSDL = HandleEvents(event);

   if(QuitSDL)
   {
       break;
   }

}

SDL_Quit();

HandleEvents() returns true if the user pressed ESC or if they closed the
window.

When I do either of these events, the program segfaults. Anyone know why
this would be?

As far as I know, you cannot have SDL_WaitEvent in a different thread, it
has to be in the main thread.

Probably SDL_Quit can also not be in another thread.


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

2009/4/1 David Doria :

When I do either of these events, the program segfaults. Anyone know why
this would be?

What segfaults?

2009/4/1 David Doria :

You can put stuff in a different thread as long as EVERYTHING for opengl is
in that thread. My application is working properly, it just crashes when I
exit.

“Stuff?”

Where does the documentation say you can call SDL_Quit() from another
thread? The docs should be more clear about this, but I am pretty
certain that many of the back-ends would not allow most SDL
subsystems to be closed in a thread that didn’t open them.

Just because it seems to work doesn’t mean it’s allowed by the API,
nor that it will work all of the time.

You should join/wait on all child threads that might be using SDL
functionality before calling SDL_Quit(), and call do all your
initialization and uninitialization of SDL from your primary thread.–
http://codebad.com/

I am doing this:

main()
{
OtherThread();
LongFunction();
otherthread->join();
}

//in the other thread
{
setup SDL (ie. get a GL context)
do all my rendering
handle events
SDL_quit when a quit event is triggered
}

That should be fine right? The SDL stuff is all in the second thread, and
main waits for it to finish (with join) before exiting.

I can’t actually figure out what is seg faulting - how would I do that?

Thanks,

DavidOn Wed, Apr 1, 2009 at 5:41 PM, Donny Viszneki <donny.viszneki at gmail.com>wrote:

2009/4/1 David Doria <@David_Doria>:

When I do either of these events, the program segfaults. Anyone know why
this would be?

What segfaults?

2009/4/1 David Doria <@David_Doria>:

You can put stuff in a different thread as long as EVERYTHING for opengl
is
in that thread. My application is working properly, it just crashes when
I
exit.

“Stuff?”

Where does the documentation say you can call SDL_Quit() from another
thread? The docs should be more clear about this, but I am pretty
certain that many of the back-ends would not allow most SDL
subsystems to be closed in a thread that didn’t open them.

Just because it seems to work doesn’t mean it’s allowed by the API,
nor that it will work all of the time.

You should join/wait on all child threads that might be using SDL
functionality before calling SDL_Quit(), and call do all your
initialization and uninitialization of SDL from your primary thread.


http://codebad.com/


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

2009/4/1 David Doria :

That should be fine right? The SDL stuff is all in the second thread, and
main waits for it to finish (with join) before exiting.

I’m not sure why it segfaults exactly, but I know that Windows is
pretty picky about doing some stuff specifically on the main thread,
and it’s usually the event handling stuff (each thread has its own
event queue, some important messages might get sent to the main
thread? I don’t remember…).–
http://pphaneuf.livejournal.com/

I’m using Fedora 10, if that makes a difference.

Thanks,

DavidOn Wed, Apr 1, 2009 at 5:49 PM, Pierre Phaneuf wrote:

2009/4/1 David Doria <@David_Doria>:

That should be fine right? The SDL stuff is all in the second thread, and
main waits for it to finish (with join) before exiting.

I’m not sure why it segfaults exactly, but I know that Windows is
pretty picky about doing some stuff specifically on the main thread,
and it’s usually the event handling stuff (each thread has its own
event queue, some important messages might get sent to the main
thread? I don’t remember…).


http://pphaneuf.livejournal.com/


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

2009/4/1 David Doria :

I can’t actually figure out what is seg faulting - how would I do that?

Any debugger will tell you. For extra points, recompile your program
(and SDL if you’re really cool) with your compiler’s debugging options
turned on.–
http://codebad.com/

I am compiling in debug mode. Actually, when I changed to release mode, it
seg faults without doing anything at all. Seemed odd…

Thanks,

DavidOn Wed, Apr 1, 2009 at 5:52 PM, Donny Viszneki <donny.viszneki at gmail.com>wrote:

2009/4/1 David Doria <@David_Doria>:

I can’t actually figure out what is seg faulting - how would I do that?

Any debugger will tell you. For extra points, recompile your program
(and SDL if you’re really cool) with your compiler’s debugging options
turned on.


http://codebad.com/


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

2009/4/1 David Doria :

I am compiling in debug mode.? Actually, when I changed to release mode, it
seg faults without doing anything at all. Seemed odd…

Ok, well now run it in GDB. Something like this:

$ gdb path/to/binary
(gdb) run

SIGSEGV received!
(gdb) bt

http://codebad.com/