P2D/P3D causes image flickering and disappearing from draw() loop?!

void setup(){
  PImage flower = loadImage("bloom.jpg");
  size(897, 565, P2D); //Line in Question
  image(flower, 472+26,86, 189,189);
}

causes flickering but the second does not, however my main project uses createGraphics() which requires P2D or P3D

void setup(){
  PImage flower = loadImage("bloom.jpg");
  size(897, 565); //Fixed line version that doesnt work in main project I have
  image(flower, 472+26,86, 189,189);
}

ezgif-3-c7f02668a1

An even bigger problem is that if I add a draw loop to this the image just disappears

PImage flower;
void setup(){
  flower = loadImage("bloom.jpg");
  size(897, 565, P2D);
  image(flower, 472+26,86, 189,189);
}
void draw(){
  rect(10,10,10,10);
}

I don’t think it is recommended to do any drawing in setup(). It is meant to, you know set things up for action in draw() cycles. And size() function should be the very first thing in setup()

Hello,

This works fine on Windows 10.

Try updatding to the latest version Processing 4.0 beta 8.

Try adding frameRate(30) to setup().

Please report what happens after trying above.

Reference:

:)

Ok I updated to the latest macOS(affecting nothing)
The frameRate did nothing
and updating to the newest beta 8 didn’t fix the problem and in fact messed up the rest of the project

Hello @SomeOne,

It does not matter where size() is in setup() as it is moved to settings() before running.

I always put it first for readable code. :)

Before:

void setup() 
  {
  size(640, 360);
  noLoop();
  }

void draw() 
  {
  background(0);
  }
After < Click here for code
/* autogenerated by Processing revision 1283 on 2022-05-26 */
import processing.core.*;
import processing.data.*;
import processing.event.*;
import processing.opengl.*;

import java.util.HashMap;
import java.util.ArrayList;
import java.io.File;
import java.io.BufferedReader;
import java.io.PrintWriter;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.IOException;

public class sketch_220526e extends PApplet {


 public void setup() 
	{
  /* size commented out by preprocessor */;
  noLoop();
	}

 public void draw() 
	{
  background(0);
	}


  public void settings() { size(640, 360); }

  static public void main(String[] passedArgs) {
    String[] appletArgs = new String[] { "sketch_220526e" };
    if (passedArgs != null) {
      PApplet.main(concat(appletArgs, passedArgs));
    } else {
      PApplet.main(appletArgs);
    }
  }
}

You can see these files in your %temp% folder.

Reference:

:)

1 Like