Discussion:
The ramifications of not calling SDL_Quit
(too old to reply)
Joel Hobson
2004-05-26 18:19:01 UTC
Permalink
I was wondering what happens if SDL_Quit is not called before the
application finishes, such as if it freezes up and needs to be
ctrl-alt-deleted out of.

Thanks

Joel
Michael Rickert
2004-05-27 09:59:14 UTC
Permalink
Post by Joel Hobson
I was wondering what happens if SDL_Quit is not
called before the
application finishes, such as if it freezes up and
needs to be
ctrl-alt-deleted out of.
Thanks
Joel
Probably undefined and OS specific. Just atexit(
SDL_Quit );.

I think on linux it segfaults, but that might be
another figment of my imagination.

Just try not to do it? 0_o




__________________________________
Do you Yahoo!?
Friends. Fun. Try the all-new Yahoo! Messenger.
http://messenger.yahoo.com/
Donny Viszneki
2004-05-27 10:26:23 UTC
Permalink
Post by Joel Hobson
such as if it freezes up and
needs to be
ctrl-alt-deleted out of.
Just atexit(SDL_Quit );.
Did you even read what he said? And the other stuff
you said wasn't even too useful. Don't fill the
mailing list with unhelpful nonsense. Besides, if
you'd read the SDL Documentation Library on the
subject, you'd know:

"...using atexit maybe be fine for small programs,
more advanced users should shut down SDL in their own
cleanup code. Plus, using atexit in a library is a
sure way to crash dynamically loaded code..."

Now onto business.

The ramifications of not SDL_Quitting are pretty
simple. First of all, all of the subsystems in SDL
allocate heap memory. If you don't uninitialize them,
you will have a memory leak. I'm not sure how serious
any such leak would be since I don't know how much
memory is allocated by any part of SDL.

I've also been told that not SDL_Quitting in *nix as
root having taken full control of video, you often
have to reboot your system, and a similar thing
happens to audio, except you can probably fix any
problem on your computer without audio, which you
can't do without video, ergo, rebooting when your
display no longer functions.

Other than that, that other guy was certainly right
about one thing: it's probably very implementation-
and platform- specific.




__________________________________
Do you Yahoo!?
Friends. Fun. Try the all-new Yahoo! Messenger.
http://messenger.yahoo.com/
Joel Hobson
2004-05-27 15:02:52 UTC
Permalink
Is it possible to call SDL_Quit from another program?

Joel
Nicolai Haehnle
2004-05-27 15:22:28 UTC
Permalink
Post by Joel Hobson
Is it possible to call SDL_Quit from another program?
Uhh... no?

Of course you could call SDL_Quit in another program, but that will try to
quit the instance of libsdl that is running in said program, not the
original program.

What's the big deal anyway? When a process crashes, unfreed heap memory is
reclaimed by the operating system. A left-open display should be closed by
the display system (e.g. X Windows).

If either the operating system or the display system fail at cleaning up the
mess that a crashed program leaves behind, it's clearly a bug in that
system, and has nothing to do with SDL at all.

cu,
Nicolai
Bob Pendleton
2004-05-27 16:43:41 UTC
Permalink
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Post by Joel Hobson
Is it possible to call SDL_Quit from another program?
Uhh... no?
Of course you could call SDL_Quit in another program, but that will try to
quit the instance of libsdl that is running in said program, not the
original program.
What's the big deal anyway? When a process crashes, unfreed heap memory is
reclaimed by the operating system. A left-open display should be closed by
the display system (e.g. X Windows).
If either the operating system or the display system fail at cleaning up the
mess that a crashed program leaves behind, it's clearly a bug in that
system, and has nothing to do with SDL at all.
What you just said is correct for Windows, now days. There were several
years during which that was not true for Windows. For X, well, mostly.
It depends on the drivers, now days 99% correct. If you are using direct
access to the graphics hardware it is often necessary to clean it up.
Most of you will never run into that situation, but some will.

It is a good idea to always call SDL_Quit() to make sure the video is
restored to and the input devices are properly reinitialized.

Bob Pendleton
cu,
Nicolai
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)
iD8DBQFAtge1sxPozBga0lwRAqRZAKCY8floZ6Y2IW4uRKMlog4nHKAXiwCg3hlT
+doVxX7OApZM8olg2qUYWRE=
=SFxC
-----END PGP SIGNATURE-----
_______________________________________________
SDL mailing list
http://www.libsdl.org/mailman/listinfo/sdl
--
+--------------------------------------+
+ Bob Pendleton: writer and programmer +
+ email: ***@Pendleton.com +
+ blog: www.Stonewolf.net +
+ web: www.GameProgrammer.com +
+--------------------------------------+
Nicolai Haehnle
2004-05-27 17:15:38 UTC
Permalink
Post by Bob Pendleton
What you just said is correct for Windows, now days. There were several
years during which that was not true for Windows. For X, well, mostly.
It depends on the drivers, now days 99% correct. If you are using direct
access to the graphics hardware it is often necessary to clean it up.
Most of you will never run into that situation, but some will.
It doesn't matter, it's still a bug in the operating system, or in X
Windows, or whatever is responsible.

Look, if the kernel failed to free heap memory that was allocated by a
process, surely you would call this a bug?
If the kernel didn't close open files automatically, surely you would call
this a bug?

Why don't you call it a bug when e.g. the X server fails to release the
mouse grab when a client crashes? Yes, there are silly bugs like that in
XFree.
Just because direct rendering and the like happens be slightly more complex,
that doesn't mean it's not a bug.

Oh well. The design of graphics on Linux is currently inherently unstable,
and I like to rant about it. I guess I'll shut up now.

cu,
Nicolai
Joel Hobson
2004-05-27 18:33:28 UTC
Permalink
Actually, I'm asking not because of my code, but out of fear that my
code will crash for some reason, or be ctrl-alt-deleted out of, before
SDL_Quit is called.
Thanks though.

Joel
Drake Wilson
2004-05-27 19:12:02 UTC
Permalink
Post by Joel Hobson
Actually, I'm asking not because of my code, but out of fear that my
code will crash for some reason, or be ctrl-alt-deleted out of, before
SDL_Quit is called.
Thanks though.
This is why SDL installs a 'parachute'. If you crash, under Unix it
generally sends SIGSEGV (or SIGBUS) to the process. SDL sets up a
handler that catches this (among other signals) so it can deinitialize
itself appropriately. On its calling TTY (if there is one), it prints
an error message indicating such:

Fatal signal: Segmentation Fault (SDL Parachute Deployed)

Under Windows I expect it would be similar.

If you supply an SDL_NOPARACHUTE flag to SDL_Init, this functionality
will be disabled.

As far as the C-A-DEL combination, this is usually handled by the OS;
under Linux it usually triggers a clean reboot which sends SIGTERM,
then SIGKILL. I'm not sure SDL catches SIGTERM; it doesn't seem to
with a short test program... ? SIGKILL, of course, is not catchable.

If the system is shutting down, of course, I estimate the utility of
calling SDL_Quit may be somewhat diminished, but I'm hesitant to give
an answer with any certainty.
Post by Joel Hobson
Joel
---> Drake Wilson
Bob Pendleton
2004-05-27 19:25:29 UTC
Permalink
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Post by Bob Pendleton
What you just said is correct for Windows, now days. There were several
years during which that was not true for Windows. For X, well, mostly.
It depends on the drivers, now days 99% correct. If you are using direct
access to the graphics hardware it is often necessary to clean it up.
Most of you will never run into that situation, but some will.
It doesn't matter, it's still a bug in the operating system, or in X
Windows, or whatever is responsible.
Heavy sigh.... No.

First off, there are a lot of platforms that SDL runs on that are not
Windows or X based. On those platforms it is clearly not a bug in
Windows or X if things don't get cleaned up.

Like I said, you are not likely to run into things like that, but that
doesn't mean they don't exist.
Look, if the kernel failed to free heap memory that was allocated by a
process, surely you would call this a bug?
Not under Windows 3.x, nor under the early versions of MacOS. Not
releasing memory was a feature and was heavily used for interprocess
communication. What version of Windows finally did away with 16 bit
compatibility?

You live in a Linux/Win32 world so you don't see this kind of thing.
Doesn't mean it doesn't still exist.
If the kernel didn't close open files automatically, surely you would call
this a bug?
I've worked on so many OSes where failing to close a file meant losing
the file that while I am always thankful when the OS flushes the buffers
and closes the files, I don't expect it. And, that includes a lot of
versions of UNIX. You don't close a file, your buffers that are still in
memory get lost.
Why don't you call it a bug when e.g. the X server fails to release the
mouse grab when a client crashes? Yes, there are silly bugs like that in
XFree.
That is a bug. The thing is that it can take a while for X to be sure
that the applications has crashed. So, if it just waits a while before
it, that is a design issue in the kernel.
Just because direct rendering and the like happens be slightly more complex,
that doesn't mean it's not a bug.
If you have to lie to a part of the system to do the direct rendering it
is not a bug if that part of the system doesn't know that your program
crapped out and fails to fix the stuff it was lied to about. There is a
lot of guilt to throw around when that happens, but no bug in the part
of the system that was lied to.
Oh well. The design of graphics on Linux is currently inherently unstable,
Again, no. Not inherently unstable. Stupid yes, but not inherently
unstable.
and I like to rant about it. I guess I'll shut up now.
I spent about five years doing commercial ports of the X server to high
end 3D graphics systems. X is a good idea, poorly executed, that became
a religion for the Xfree86 folks. Now that X.org seems to back in charge
and Kieth Packard is leading things we have a chance to get serious
graphics on UNIX again.

People don't like to hear it, but XFree86 held back development of
decent graphics on UNIX/Linux for 10 years.

You want to rant about X feel free to email me privately, I can rant
about X with the best of them.

Bob Pendleton
cu,
Nicolai
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)
iD8DBQFAtiI7sxPozBga0lwRAkzXAJ9VLeQ0vQQyMQ3aluuhUZLEEymCnACgyjjV
OGXbMupX0OpfuCgxxNpUtEk=
=qVfc
-----END PGP SIGNATURE-----
_______________________________________________
SDL mailing list
http://www.libsdl.org/mailman/listinfo/sdl
--
+--------------------------------------+
+ Bob Pendleton: writer and programmer +
+ email: ***@Pendleton.com +
+ blog: www.Stonewolf.net +
+ web: www.GameProgrammer.com +
+--------------------------------------+
Gabriele Greco
2004-05-28 11:16:16 UTC
Permalink
Post by Nicolai Haehnle
If either the operating system or the display system fail at cleaning up the
mess that a crashed program leaves behind, it's clearly a bug in that
system, and has nothing to do with SDL at all.
Well, a crash (or an exit without SDL_Quit()) of a fullscreen SDL app in
X11 compiled with SDL_INIT_NO_PARACHUTE left the desktop to the
fullscreen app resolution (that is often far lower than the original
desktop res).

And as told by other there are target OSes without resource tracking at
all, except the one provided by the standard C library.

For instance in AmigaOS if you do something like:

int main()
{
// open system libraries
Window *w = OpenWindowTags(TAG_DONE);
}

The program exits leaving a nice window opened on the screen :) (and a
few system libraries in the background).

If SDL has certain rules (atexit(SDL_Quit) is an example, another
popular one is the need to handle events on the SDL_SetVideoMode()
calling thread) is because it's a multiplatform API.

Bye,
Gabry
Alan Wolfe
2004-05-27 15:24:12 UTC
Permalink
from the kinds of questions your asking, your program design is serisouly
suspicious for being bad, like when someone says they actualy NEED to use
goto and there's no other way.

rethink your design, you should be able to call SDL_Quit at the end of your
program, no one else has had the problem of not being able to call it when
they need to.

----- Original Message -----
From: "Joel Hobson" <***@gmail.com>
To: "A list for developers using the SDL library. (includes SDL-announce)"
<***@libsdl.org>
Sent: Thursday, May 27, 2004 8:02 AM
Subject: Re: [SDL] The ramifications of not calling SDL_Quit
Post by Joel Hobson
Is it possible to call SDL_Quit from another program?
Joel
_______________________________________________
SDL mailing list
http://www.libsdl.org/mailman/listinfo/sdl
Simon Ejsing
2004-05-28 08:43:50 UTC
Permalink
Post by Alan Wolfe
from the kinds of questions your asking, your program design is serisouly
suspicious for being bad, like when someone says they actualy NEED to use
goto and there's no other way.
rethink your design, you should be able to call SDL_Quit at the end of your
program, no one else has had the problem of not being able to call it when
they need to.
I think your missing the point... it doesn't have to do with his code,
consider any program that uses SDL, run it and then on Unix:

kill -9 <pid>

SDL_Quit() will _not_ be called, the program is simply unloaded from memmory.
Not much to do about this.
--
Simon Ejsing, Systemudvikler
esoft ApS, http://www.esoft.dk
Skibhusvej 52C, DK-5000 Odense C.
Tlf: 70 222 466, Fax: 63 122 466
Donny Viszneki
2004-05-28 11:29:04 UTC
Permalink
Post by Alan Wolfe
Post by Alan Wolfe
from the kinds of questions your asking, your
program design is serisouly
Post by Alan Wolfe
suspicious for being bad, like when someone says
they actualy NEED to use
Post by Alan Wolfe
goto and there's no other way.
rethink your design, you should be able to call
SDL_Quit at the end of your
Post by Alan Wolfe
program, no one else has had the problem of not
being able to call it when
Post by Alan Wolfe
they need to.
I think your missing the point... it doesn't have
to do with his code,
consider any program that uses SDL, run it and then
kill -9 <pid>
SDL_Quit() will _not_ be called, the program is
simply unloaded from memmory.
Not much to do about this.
I was just thinking, if your program froze, could you
manually `kill -SIGSEGV pid` in order to make sure the
SDL parachute gets called? What happens if you send
SIGTERM?
Post by Alan Wolfe
--
Simon Ejsing, Systemudvikler
esoft ApS, http://www.esoft.dk
Skibhusvej 52C, DK-5000 Odense C.
Tlf: 70 222 466, Fax: 63 122 466
_______________________________________________
SDL mailing list
http://www.libsdl.org/mailman/listinfo/sdl
__________________________________
Do you Yahoo!?
Friends. Fun. Try the all-new Yahoo! Messenger.
http://messenger.yahoo.com/
Simon Ejsing
2004-05-28 11:43:14 UTC
Permalink
Post by Donny Viszneki
I was just thinking, if your program froze, could you
manually `kill -SIGSEGV pid` in order to make sure the
SDL parachute gets called? What happens if you send
SIGTERM?
Kill with SIGSEGV would cause the parachute to deploy, I can't say for
SIGTERM, but you could try it.
--
Simon Ejsing, Systemudvikler
esoft ApS, http://www.esoft.dk
Skibhusvej 52C, DK-5000 Odense C.
Tlf: 70 222 466, Fax: 63 122 466
Michael Rickert
2004-05-27 19:10:43 UTC
Permalink
Post by Donny Viszneki
Post by Joel Hobson
such as if it freezes up and
needs to be
ctrl-alt-deleted out of.
Just atexit(SDL_Quit );.
Did you even read what he said? And the other stuff
you said wasn't even too useful.
Yes, and here, let me reformat it for you, with better
clarity (aka, re-aranged):

---
Post by Donny Viszneki
I was wondering what happens if SDL_Quit is not
called before the
application finishes,
I think on linux it segfaults, but that might be
another figment of my imagination. (aka: not sure, and
not on my linux box to check it, and SDL not installed
on my laptop)

The "official" effect is probably "undefined", and the
actual effect(s) OS specific.

Just try not to do leave out the SDL_Quit. The
simplest way is to do this is to simply atexit(
SDL_Quit );.

---
Post by Donny Viszneki
Don't fill the
mailing list with unhelpful nonsense.
Like laying out flamebait with bashing people
needlessly <_<.
Post by Donny Viszneki
Besides, if
you'd read the SDL Documentation Library on the
"...using atexit maybe be fine for small programs,
Apparently garbage in your not so humble opinion...
Post by Donny Viszneki
more advanced users should shut down SDL in their
own cleanup code.
Makes sense? It puts everything together nice and
managable... means easier code mantinence, no?
Post by Donny Viszneki
Plus, using atexit in a library is a
sure way to crash dynamically loaded code..."
I'm assuming this is talking about the functions
usually found in dlfcn.h?
Post by Donny Viszneki
*snips*
Other than that, that other guy was certainly right
about one thing: it's probably very implementation-
and platform- specific.
This comment being the majority of my post >_>;

It wouldn't hurt to be polite... it's a rather
necessary skill (I believe) for aquiring those venture
capitalists... and it's also a favor to those of us on
the board.




__________________________________
Do you Yahoo!?
Friends. Fun. Try the all-new Yahoo! Messenger.
http://messenger.yahoo.com/
Donny Viszneki
2004-05-28 11:19:44 UTC
Permalink
Post by Michael Rickert
Post by Donny Viszneki
Post by Joel Hobson
such as if it freezes up and
needs to be
ctrl-alt-deleted out of.
Just atexit(SDL_Quit );.
Did you even read what he said? And the other
stuff
Post by Donny Viszneki
you said wasn't even too useful.
Yes, and here, let me reformat it for you, with
better
---
Post by Donny Viszneki
I was wondering what happens if SDL_Quit is not
called before the
application finishes,
I think on linux it segfaults, but that might be
another figment of my imagination. (aka: not sure,
and
not on my linux box to check it, and SDL not
installed
on my laptop)
The "official" effect is probably "undefined", and
the
actual effect(s) OS specific.
Just try not to do leave out the SDL_Quit. The
simplest way is to do this is to simply atexit(
SDL_Quit );.
---
Post by Donny Viszneki
Don't fill the
mailing list with unhelpful nonsense.
Like laying out flamebait with bashing people
needlessly <_<.
It wouldn't be /flamebait/ if you didn't react to it.
Your response to my comments were equally as unhelpful
as your original email in this thread. Perhaps my
response is setting an equally bad precedent, but I
feel it quite pertinent to point out that if you would
just agree to the notion that WASTING the mailing
list's time IS BAD, then you wouldn't have even
responded to that, except in a personal form. I am
posting this to the mailing list in hopes of
preventing similar responses to "flamebait" on the
mailing list, and this should not be interpreted as a
precedent to have arguments publically on the list.
Post by Michael Rickert
Post by Donny Viszneki
Besides, if
you'd read the SDL Documentation Library on the
"...using atexit maybe be fine for small programs,
Apparently garbage in your not so humble opinion...
Comments like these are UNNECESSARY and WASTE readers'
time! Valid your opinion may be, it isn't helpful for
readers to know how you feel about how humble, or
arrogant, or fascist, or gay you might think I am.
Your opinions do not help the readers of this mailing
list. Again, please interpret my remark here as an
attempt to stifle further useless etiquette-related
commentary.
Post by Michael Rickert
Post by Donny Viszneki
more advanced users should shut down SDL in their
own cleanup code.
Makes sense? It puts everything together nice and
managable... means easier code mantinence, no?
What the SDL Documentation Library authors were
clearly trying to relay is a well known FILO atexit
behavior. This is not always the desired order of
resource destruction, and is only suitable for
programs that have no need for resource allocation
other than "Allocate resources when my application
begins, and free them when my application ends," ergo,
"small programs."
Post by Michael Rickert
Post by Donny Viszneki
Plus, using atexit in a library is a
sure way to crash dynamically loaded code..."
I'm assuming this is talking about the functions
usually found in dlfcn.h?
And similar facilities like Windows Dynamically Linked
Libraries.
Post by Michael Rickert
Post by Donny Viszneki
*snips*
Other than that, that other guy was certainly
right
Post by Donny Viszneki
about one thing: it's probably very
implementation-
Post by Donny Viszneki
and platform- specific.
This comment being the majority of my post >_>;
It wouldn't hurt to be polite... it's a rather
necessary skill (I believe) for aquiring those
venture
capitalists... and it's also a favor to those of us
on
the board.
I don't usually come of as being rude, if you'd let
something like that pass the first time it happens
then you wouldn't waste your time and others' by
spamming the mailing list with lessons on etiquette,
or venture capital acquisition (what makes you think
I'd be anything less than an obsequious ass-kissing
bitch for someone considering sponsoring me as a
project developer, is beyond me.)
Post by Michael Rickert
__________________________________
Do you Yahoo!?
Friends. Fun. Try the all-new Yahoo! Messenger.
http://messenger.yahoo.com/
_______________________________________________
SDL mailing list
http://www.libsdl.org/mailman/listinfo/sdl
__________________________________
Do you Yahoo!?
Friends. Fun. Try the all-new Yahoo! Messenger.
http://messenger.yahoo.com/
Sean Ridenour
2004-05-28 05:23:11 UTC
Permalink
Post by Donny Viszneki
Post by Joel Hobson
such as if it freezes up and
needs to be
ctrl-alt-deleted out of.
Just atexit(SDL_Quit );.
Did you even read what he said? And the other stuff
you said wasn't even too useful. Don't fill the
mailing list with unhelpful nonsense. Besides, if
you'd read the SDL Documentation Library on the
"...using atexit maybe be fine for small programs,
more advanced users should shut down SDL in their own
cleanup code. Plus, using atexit in a library is a
sure way to crash dynamically loaded code..."
So just do:
int main(int argc, char **argv) {
blah blah blah
atexit(my_cleanup_func);
blah blah blah
}

void my_cleanup_func(void) {
clean up stuff
SDL_Quit();
}

And I doubt the thread starter was writing a library.

-Sean Ridenour
Continue reading on narkive:
Loading...