Segfault in SDL_JoystickClose()

Not much of an issue, but I’m not sure if this is supposed to be safe or not:

Calling SDL_JoystickClose() after closing SDL may cause a segfault.
(SDL 1.2.14, Linux/x86_64)

Normal application code would never do that, but it can easily happen when
wrapping the API in a language with automatic memory management. I deal with
it like this in my joystick wrapper destructor:

if(j->joystick && SDL_WasInit(SDL_INIT_JOYSTICK))
	SDL_JoystickClose(j->joystick);

…which is perfectly fine by me in this case - although personally, I prefer
it when APIs don’t pull things out from under the application, or at least do
it safely. :-)–
//David Olofson - Consultant, Developer, Artist, Open Source Advocate

.— Games, examples, libraries, scripting, sound, music, graphics —.
| http://consulting.olofson.net http://olofsonarcade.com |
’---------------------------------------------------------------------’

Not much of an issue, but I’m not sure if this is supposed to be safe or
not:

Calling SDL_JoystickClose() after closing SDL may cause a segfault.
(SDL 1.2.14, Linux/x86_64)

Normal application code would never do that, but it can easily happen when
wrapping the API in a language with automatic memory management. I deal
with
it like this in my joystick wrapper destructor:

   if(j->joystick && SDL_WasInit(SDL_INIT_JOYSTICK))
           SDL_JoystickClose(j->joystick);

…which is perfectly fine by me in this case - although personally, I
prefer
it when APIs don’t pull things out from under the application, or at least
do
it safely. :slight_smile:


//David Olofson - Consultant, Developer, Artist, Open Source Advocate

.— Games, examples, libraries, scripting, sound, music, graphics —.
| http://consulting.olofson.net http://olofsonarcade.com |
’---------------------------------------------------------------------’


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

Hi,

thanks for this info.

I’d think that many of the APIs would not work sanely after SDL has quit?On Wed, Aug 31, 2011 at 2:30 PM, David Olofson wrote:

Hi, we (the SDL Perl ppl) doing something like:
Perl_call_atexit( SDL_quit )
This is called automagically when perl shuts down. The programs mustnt call SDL_quit unless they want to reinitialize it afterwards again.

Cheers, FROGGS

Ren? Dudfield hat geschrieben:>On Wed, Aug 31, 2011 at 2:30 PM, David Olofson wrote:

Not much of an issue, but I’m not sure if this is supposed to be safe or
not:

Calling SDL_JoystickClose() after closing SDL may cause a segfault.
(SDL 1.2.14, Linux/x86_64)

Normal application code would never do that, but it can easily happen when
wrapping the API in a language with automatic memory management. I deal
with
it like this in my joystick wrapper destructor:

   if(j->joystick && SDL_WasInit(SDL_INIT_JOYSTICK))
           SDL_JoystickClose(j->joystick);

…which is perfectly fine by me in this case - although personally, I
prefer
it when APIs don’t pull things out from under the application, or at least
do
it safely. :slight_smile:


//David Olofson - Consultant, Developer, Artist, Open Source Advocate

.— Games, examples, libraries, scripting, sound, music, graphics —.
| http://consulting.olofson.net http://olofsonarcade.com |
’---------------------------------------------------------------------’


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

Hi,

thanks for this info.

I’d think that many of the APIs would not work sanely after SDL has quit?


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

I’d think that many of the APIs would not work sanely after SDL has quit?

Including that one. I’d argue that this isn’t a bug, since you have to
pass SDL_JoystickClose() a pointer that SDL gave you while initialized.

SDL_Quit() cleaned this pointer up for you.

(Actually: bug, no it didn’t. But it should!)

–ryan.

SDL_Quit() cleaned this pointer up for you.

(Actually: bug, no it didn’t. But it should!)

And now it does!

1.3 branch: http://hg.libsdl.org/SDL/rev/173d28fd4be4
1.2 branch: http://hg.libsdl.org/SDL/rev/772a7dbfbccf

–ryan.

nice one!

A little note that might be useful for other dyn languages…
pygame for python works by registering a quit function for each SDL module.
So when it quits, it does various cleanups before closing SDL. The joystick
module loops through the joysticks and closes them, then quits the joystick
subsystem. The same function is reused if we just quit the joystick
subsystem.On Thu, Sep 1, 2011 at 10:35 AM, Ryan C. Gordon wrote:

SDL_Quit() cleaned this pointer up for you.

(Actually: bug, no it didn’t. But it should!)

And now it does!

1.3 branch: http://hg.libsdl.org/SDL/rev/**173d28fd4be4http://hg.libsdl.org/SDL/rev/173d28fd4be4
1.2 branch: http://hg.libsdl.org/SDL/rev/**772a7dbfbccfhttp://hg.libsdl.org/SDL/rev/772a7dbfbccf

–ryan.

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