We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › exit()/stop() confusion...
Page Index Toggle Pages: 1
exit()/stop() confusion... (Read 515 times)
exit()/stop() confusion...
Mar 18th, 2008, 8:31am
 
Hello,

I've been playing around with Processing for a couple of hours now, and managed to put together a little RGB LED mixing program (three ControlP5 sliders controlling a three-color RGB LED hooked up to an Arduino). The program worked as expected, except that the LED was left on when the Processing window was closed. So I overloaded the stop() method to write a string of zeros to the serial port when the window closes...

This approach works just fine when running the sketch within the Processing environment, but if I export the application, the overloaded stop() method is no longer being called. I know I must be missing something stupid, but I can't figure it out! Here's my stop() code:


void stop() {
 outputString[0] = 0; // R
 outputString[1] = 0; // G
 outputString[2] = 0; // B
 
 port.write(outputString);
}


I searched the boards and saw some talk of calling super.stop() at the end of the above code, but that didn't help... Any other ideas?

Thanks!
Al.
Re: exit()/stop() confusion...
Reply #1 - Mar 18th, 2008, 10:20am
 
Try changing it to
Code:
public void stop()
{
outputString[0] = 0; // R
outputString[1] = 0; // G
outputString[2] = 0; // B

port.write(outputString);
super.stop();
}


Note the "public"
Re: exit()/stop() confusion...
Reply #2 - Mar 18th, 2008, 3:46pm
 
Hi John,

Thanks for your reply. I tried your suggestion, but no luck... :-\

Any other ideas?

Best,
Al.
Re: exit()/stop() confusion...
Reply #3 - Aug 2nd, 2009, 6:12pm
 
alk509 - did you ever resolve this ?

I am having same issue, stop is not called when using export as application.

OSX 10.5.7
Processing 1.0.5
public stop declaration &  super.stop() as last command in method.
Re: exit()/stop() confusion...
Reply #4 - Aug 3rd, 2009, 3:02am
 
From the PApplet core reference:
Quote:
public void stop()

   Called by the browser or applet viewer to inform this applet that it should stop its execution.

   Unfortunately, there are no guarantees from the Java spec when or if stop() will be called (i.e. on browser quit, or when moving between web pages), and it's not always called.

   Overrides:
       stop in class java.applet.Applet

In other words, it is called automatically by Java when running an applet.
I see in the source that it is also called by destroy() (also invoked automatically) and in the main loop when the animation thread is stopped. And some other places.

All this is useless if the system doesn't give the Java program a chance to stop gracefully.
Maybe you can look at Revelations on Java signal handling and termination article and see if you can handle the termination signal...
Page Index Toggle Pages: 1