Bug 1563 : Not possible to add shutdown hooks
Last modified: 2010-05-19 05:54




Status:
RESOLVED
Resolution:
DUPLICATE of bug 183
Priority:
P2
Severity:
normal

 

Reporter:
Far alla
Assigned To:
fry

Attachment Type Created Size Actions

Description:   Opened: 2010-05-19 02:54
Since processing.core.PApplet.main(String[], PApplet) registers
System.exit(0); as the event-handler for shutting down, it is not possible
to add any shutdown code in Processing, to e.g. release system-resources
like serial interfaces.

A better solution is to replace System.exit(0); with applet.destroy(); in
processing.core.PApplet.main(...).new MouseAdapter()
{...}.mousePressed(MouseEvent) (line 7249 in PApplet.java in svn-tag 1.1)
and in processing.core.PApplet.main(...).new WindowAdapter()
{...}.windowClosing(WindowEvent) (line 7330 in same version).

If done so, the user could easily override PApplet.destroy() to add
shutdown-code.

In fact System.exit(int) should NEVER be called! I think there are more
occurences. Theses should also be checked.
Additional Comment #1 From fry 2010-05-19 05:32
That's what stop() is for, in part because not everything (perhaps not even
most things anymore) created with Processing are applets. Though stop()
still has its problems, seen in bug #183.
Additional Comment #2 From Far alla 2010-05-19 05:48
Fry, the Problem is, that stop() is ONLY called by the ESCAPE-Key listener.
Instead, when closing the applet either by closing the window or by
clicking the "close"-label, the VM is forced to shut down whith no chance
to perform anything.

Furthermore, bug #183 should read as

"start() is called by the appletviewer, but destroy() is guaranteed to
be NOT called. "


Thus, I advice to replace it with applet.destroy() which only calls
applet.stop(). So these would be equivalent.
Another way would be to use exit() instead.


Additional Comment #3 From fry 2010-05-19 05:54


*** This bug has been marked as a duplicate of 183 ***