Clear the background outside draw function in Processing 3?

edited October 2015 in How To...

Hello, I have a Processing Program that draws a file on canvas. The file is selected dynamically by the user.

void setup() {
  size(300, 300);
  text("Select a file...", 20, 30);
  selectInput("Select a file:", "fileSelected");

void fileSelected(File selection) {
  if (selection == null) {
  } else {
    // v other things...

When I upgraded to Processing 3 I realised that the background(0) doesn't executes. I believe that none of the draw specific functions don't longer work outside draw() and setup(). Is there any way to accomplish this again? Also, I noticed that I can't pass variables to size() anymore, and I must strong type them.



  • edited October 2015 Answer ✓
    • Even for Processing 2 & 1, modifying the "canvas" outside the "Animation" Thread was never a good idea.
    • Seems like Processing 3 is even more sensible to that than the older versions.
    • selectInput() and its siblings are run by a separate Thread.
    • Therefore we can't use any "drawing" related API there like background() for example.
    • A possible approach would be to set a boolean in order to flag a File was successfully selected.
    • Within draw(), keep polling that boolean.
    • Once it becomes true, do the stuff that you were attempting to do from selectInput().
    • And set that boolean back to false afterwards.
Sign In or Register to comment.