From f373e9db464131aa87f00d02011498fc7db90681 Mon Sep 17 00:00:00 2001 From: benfry Date: Sun, 25 Nov 2012 18:49:41 +0000 Subject: [PATCH] deal with potential race condition on sketch resize (issue 697) --- core/src/processing/core/PApplet.java | 57 ++++++----- core/todo.txt | 138 +++++++++++++------------- 2 files changed, 103 insertions(+), 92 deletions(-) diff --git a/core/src/processing/core/PApplet.java b/core/src/processing/core/PApplet.java index 01bd8accd..dca3f55fa 100644 --- a/core/src/processing/core/PApplet.java +++ b/core/src/processing/core/PApplet.java @@ -348,9 +348,12 @@ public class PApplet extends Applet */ public boolean defaultSize; - volatile boolean resizeRequest; - volatile int resizeWidth; - volatile int resizeHeight; + /** Storage for the current renderer size to avoid re-allocation. */ + Dimension currentSize = new Dimension(); + +// volatile boolean resizeRequest; +// volatile int resizeWidth; +// volatile int resizeHeight; /** * ( begin auto-generated from pixels.xml ) @@ -891,12 +894,12 @@ public class PApplet extends Applet addComponentListener(new ComponentAdapter() { @Override public void componentResized(ComponentEvent e) { - Component c = e.getComponent(); - //System.out.println("componentResized() " + c); - Rectangle bounds = c.getBounds(); - resizeRequest = true; - resizeWidth = bounds.width; - resizeHeight = bounds.height; +// Component c = e.getComponent(); +// //System.out.println("componentResized() " + c); +// Rectangle bounds = c.getBounds(); +// resizeRequest = true; +// resizeWidth = bounds.width; +// resizeHeight = bounds.height; if (!looping) { redraw(); @@ -968,8 +971,7 @@ public class PApplet extends Applet debug("un-pausing thread"); synchronized (pauseObject) { - debug("un-pausing thread 2"); - debug("start() calling pauseObject.notify()"); + debug("start() calling pauseObject.notifyAll()"); // try { pauseObject.notifyAll(); // wake up the animation thread debug("un-pausing thread 3"); @@ -1471,13 +1473,13 @@ public class PApplet extends Applet ////////////////////////////////////////////////////////////// - protected void resizeRenderer(int iwidth, int iheight) { -// println("resizeRenderer request for " + iwidth + " " + iheight); - if (width != iwidth || height != iheight) { -// println(" former size was " + width + " " + height); - g.setSize(iwidth, iheight); - width = iwidth; - height = iheight; + protected void resizeRenderer(int newWidth, int newHeight) { + debug("resizeRenderer request for " + newWidth + " " + newHeight); + if (width != newWidth || height != newHeight) { + debug(" former size was " + width + " " + height); + g.setSize(newWidth, newHeight); + width = newWidth; + height = newHeight; } } @@ -2001,9 +2003,15 @@ public class PApplet extends Applet // Don't resize the renderer from the EDT (i.e. from a ComponentEvent), // otherwise it may attempt a resize mid-render. - if (resizeRequest) { - resizeRenderer(resizeWidth, resizeHeight); - resizeRequest = false; +// if (resizeRequest) { +// resizeRenderer(resizeWidth, resizeHeight); +// resizeRequest = false; +// } + if (g != null) { + getSize(currentSize); + if (currentSize.width != g.width || currentSize.height != g.height) { + resizeRenderer(currentSize.width, currentSize.height); + } } // render a single frame @@ -2074,7 +2082,7 @@ public class PApplet extends Applet //synchronized public void handleDisplay() { public void handleDraw() { - debug("handleDraw() " + g + " " + looping + " " + redraw); + debug("handleDraw() " + g + " " + looping + " " + redraw + " valid:" + this.isValid() + " visible:" + this.isVisible()); if (g != null && (looping || redraw)) { if (!g.canDraw()) { debug("g.canDraw() is false"); @@ -3713,7 +3721,10 @@ public class PApplet extends Applet thread = null; // shut down renderer - if (g != null) g.dispose(); + if (g != null) { + g.dispose(); + } + // run dispose() methods registered by libraries handleMethods("dispose"); } } diff --git a/core/todo.txt b/core/todo.txt index 1f0158f4e..a82b78413 100644 --- a/core/todo.txt +++ b/core/todo.txt @@ -29,7 +29,7 @@ A Implement arc() with modes on OpenGL A http://code.google.com/p/processing/issues/detail?id=1406 X relative coordinates not updated properly on closepath with SVG files X http://code.google.com/p/processing/issues/detail?id=1058 -X add XML.getLong() (also update Android) +X add XML.getLong() (also updated Android) X http://code.google.com/p/processing/issues/detail?id=1378 X beginShape(QUAD) not working with Java2D X http://code.google.com/p/processing/issues/detail?id=1365 @@ -40,6 +40,15 @@ A http://code.google.com/p/processing/issues/detail?id=1169 X image resizing is ugly (just use java2d?) o also deal with copy()/blend() inaccuracies X http://code.google.com/p/processing/issues/detail?id=332 +o key/mouse events have concurrency problems with noLoop() +X http://code.google.com/p/processing/issues/detail?id=187 +o need to say "no drawing inside mouse/key events w/ noLoop" +X changed to reference issue +X redraw() doesn't work from within draw() +X http://code.google.com/p/processing/issues/detail?id=195 +X make note for Casey to include this in the reference +X Potential race condition when resizing sketches +X http://code.google.com/p/processing/issues/detail?id=697 andres (cleanup) A when turning smoothing on, internal lines of shapes are visible @@ -119,6 +128,63 @@ if (external && event.getNative() instanceof java.awt.event.KeyEvent && exit(); } +stop() mess +_ in PApplet.main(), windowClosing() should probably be calling 'exit()' +_ or rather, we should never call System.exit(0), ja? +_ dispose() method in PApplet should be empty so ppl can override +_ move that stuff to destroy() +_ pause()/resume() need to work on the desktop side as well +_ notify ddf when pause/resume implemented +_ stop() not called in 1.5 +_ http://code.google.com/p/processing/issues/detail?id=636 +_ In reply to c#1, I noticed that dispose() is getting called. stop() isn't. +_ static mode sketches seem to break ESC... noLoop() problem? +_ need to find another way to get ESC on static mode +_ b/c static mode sketches *do* finish because they have no draw() +_ sort out destroy(), stop(), pause() et al +_ ColorSelector should stop/pause when not visible +_ right now it's doing a low-level looping +_ start()/stop() perform like onPause()/onResume() +_ all of which call pause() and resume() +_ destroy() (from Applet) calls (our) dispose() +_ destroy() shouldn't call exit()... change from lonnen +_ calls ((PApplet)this).exit() instead of stop() (since stop is pause) +_ notes +_ exit() should do the actual exit +_ if inside draw, let it finish the loop +_ if not looping, need to do it immediately +_ does stop() unwind the thread, or does the thread unwind call stop? +_ browser will call start() and stop() methods +_ need to figure out start/stop signals coming from the browser +_ is it dispose/destroy? +_ stop() not getting called +_ http://code.google.com/p/processing/issues/detail?id=43 +_ major problem for libraries +_ and start() is supposedly called by the applet viewer +_ http://java.sun.com/j2se/1.4.2/docs/api/java/applet/Applet.html#start() +_ need to track this stuff down a bit +_ when closing a sketch via the close box, make sure stop() getting called +X found a problem for release 0133 +_ test to see if it's working +_ what's up with stop() vs exit()? +_ need to get this straightened for p5 (i.e. bc has this problem) +_ make sure the main() doesn't exit until the applet has finished +_ i.e. problem with main calling itself multiple times in Alpheus +_ if exit() (or stop) is called, then System.exit() gets called, +_ even though the main() wants to keep going +_ hitting ESC in a running noLoop()ed sketch won't close the sketch? +o work through serial examples +_ noloop ref even says that redraw will be called on resize, make sure it is +_ focus not coming through, ESC no longer working(?) +_ stop() not called in 1.5 when closing the sketch window +_ http://code.google.com/p/processing/issues/detail?id=636 +_ hitting cmd-q when an applet is running quits p5 (on macosx) +_ but cmd-q when running externally is ok because it just quits +_ is there a way to catch cmd-q when running a sketch? +_ so that it could avoid quitting if the sketch hasn't been stopped +_ or if the sketch window is foremost +_ maybe a hack where a new menubar is added? + _ how to handle get(x, y, w, h) when off screen? _ http://code.google.com/p/processing/issues/detail?id=925 @@ -314,8 +380,6 @@ _ Update http://wiki.processing.org/w/Troubleshooting#Flicker _ http://code.google.com/p/processing/issues/detail?id=775 _ thread() causes weird flickering _ http://code.google.com/p/processing/issues/detail?id=742 -_ Potential race condition when resizing sketches -_ http://code.google.com/p/processing/issues/detail?id=697 _ move requestFocusInWindow() to safter EDT place _ PUtil -> move match(), lots of other non-gui functions into own class @@ -441,72 +505,6 @@ _ new PGraphics(... OutputStream) _ http://code.google.com/p/processing/issues/detail?id=246 _ already added for PDF, just need to work out the API -looping/events -_ key and mouse events delivered out of order -_ http://code.google.com/p/processing/issues/detail?id=79 -_ key/mouse events have concurrency problems with noLoop() -_ http://code.google.com/p/processing/issues/detail?id=187 -_ need to say "no drawing inside mouse/key events w/ noLoop" -_ redraw() doesn't work from within draw() -_ http://code.google.com/p/processing/issues/detail?id=195 - -stop() mess -_ in PApplet.main(), windowClosing() should probably be calling 'exit()' -_ or rather, we should never call System.exit(0), ja? -_ dispose() method in PApplet should be empty so ppl can override -_ move that stuff to destroy() -_ pause()/resume() need to work on the desktop side as well -_ notify ddf when pause/resume implemented -_ stop() not called in 1.5 -_ http://code.google.com/p/processing/issues/detail?id=636 -_ In reply to c#1, I noticed that dispose() is getting called. stop() isn't. -_ static mode sketches seem to break ESC... noLoop() problem? -_ need to find another way to get ESC on static mode -_ b/c static mode sketches *do* finish because they have no draw() -_ sort out destroy(), stop(), pause() et al -_ ColorSelector should stop/pause when not visible -_ right now it's doing a low-level looping -_ start()/stop() perform like onPause()/onResume() -_ all of which call pause() and resume() -_ destroy() (from Applet) calls (our) dispose() -_ destroy() shouldn't call exit()... change from lonnen -_ calls ((PApplet)this).exit() instead of stop() (since stop is pause) -_ notes -_ exit() should do the actual exit -_ if inside draw, let it finish the loop -_ if not looping, need to do it immediately -_ does stop() unwind the thread, or does the thread unwind call stop? -_ browser will call start() and stop() methods -_ need to figure out start/stop signals coming from the browser -_ is it dispose/destroy? -_ stop() not getting called -_ http://code.google.com/p/processing/issues/detail?id=43 -_ major problem for libraries -_ and start() is supposedly called by the applet viewer -_ http://java.sun.com/j2se/1.4.2/docs/api/java/applet/Applet.html#start() -_ need to track this stuff down a bit -_ when closing a sketch via the close box, make sure stop() getting called -X found a problem for release 0133 -_ test to see if it's working -_ what's up with stop() vs exit()? -_ need to get this straightened for p5 (i.e. bc has this problem) -_ make sure the main() doesn't exit until the applet has finished -_ i.e. problem with main calling itself multiple times in Alpheus -_ if exit() (or stop) is called, then System.exit() gets called, -_ even though the main() wants to keep going -_ hitting ESC in a running noLoop()ed sketch won't close the sketch? -o work through serial examples -_ noloop ref even says that redraw will be called on resize, make sure it is -_ focus not coming through, ESC no longer working(?) -_ stop() not called in 1.5 when closing the sketch window -_ http://code.google.com/p/processing/issues/detail?id=636 -_ hitting cmd-q when an applet is running quits p5 (on macosx) -_ but cmd-q when running externally is ok because it just quits -_ is there a way to catch cmd-q when running a sketch? -_ so that it could avoid quitting if the sketch hasn't been stopped -_ or if the sketch window is foremost -_ maybe a hack where a new menubar is added? - //////////////////////////////////////////////////////////////////// @@ -635,6 +633,8 @@ _ http://www.adobe.com/svg/eol.html CORE / OpenGL (Andres) +_ ortho() issues +_ http://code.google.com/p/processing/issues/detail?id=1240 _ hint(DISABLE_PERSPECTIVE_CORRECTED_STROKE) _ textureWrap(CLAMP / REPEAT) _ implement setImpl() instead of set() inside PGraphicsOpenGL