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

**URL:** <https://discourse.processing.org/t/p2d-p3d-causes-image-flickering-and-disappearing-from-draw-loop/36877>\
**Category:** Coding Questions\
**Created:** [May 13, 2022, 6:56pm UTC](https://discourse.processing.org/t/p2d-p3d-causes-image-flickering-and-disappearing-from-draw-loop/36877 "2022-05-13T18:56:25Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![AstroPeng](https://avatars.discourse-cdn.com/v4/letter/a/c67d28/32.png) [@AstroPeng](https://discourse.processing.org/u/AstroPeng)\
**Post date:** [May 13, 2022, 6:56pm UTC](https://discourse.processing.org/t/p2d-p3d-causes-image-flickering-and-disappearing-from-draw-loop/36877/1 "2022-05-13T18:56:25Z")

</div>

```auto
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

```auto
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](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/3X/5/0/5091991ab3d8c1e9b5a2455eda2a262f722feb9e.gif)

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

```auto
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);
}

```

---

<div class="post-metadata">

**Author:** ![SomeOne](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/someone/32/8639_2.png) [@SomeOne](https://discourse.processing.org/u/SomeOne)\
**Post date:** [May 14, 2022, 7:27am UTC](https://discourse.processing.org/t/p2d-p3d-causes-image-flickering-and-disappearing-from-draw-loop/36877/2 "2022-05-14T07:27:05Z")

</div>

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()

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [May 15, 2022, 1:07am UTC](https://discourse.processing.org/t/p2d-p3d-causes-image-flickering-and-disappearing-from-draw-loop/36877/3 "2022-05-15T01:07:28Z")

</div>

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:

> [@Big Sur and new Macs](https://discourse.processing.org/t/big-sur-and-new-macs/25374):
>
> Hi all, Wondering if anyone willing to share initial experiences with Processing on the new Mac hardware and “Big Sur” OS11 (OSX 11? OSXI?) … For context, we have a number of semi-permanent and permanent installations that use Mac minis and run Processing/Java full-out, thousands of threads, 24/7 type things, and sometimes require external hardware like sound cards etc. Wondering what kind of change we should be prepared for if we start using the new silicon and operating system. Catalin…

`:)`

---

<div class="post-metadata">

**Author:** ![AstroPeng](https://avatars.discourse-cdn.com/v4/letter/a/c67d28/32.png) [@AstroPeng](https://discourse.processing.org/u/AstroPeng)\
**Post date:** [May 17, 2022, 7:09pm UTC](https://discourse.processing.org/t/p2d-p3d-causes-image-flickering-and-disappearing-from-draw-loop/36877/4 "2022-05-17T19:09:29Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [May 26, 2022, 5:27pm UTC](https://discourse.processing.org/t/p2d-p3d-causes-image-flickering-and-disappearing-from-draw-loop/36877/5 "2022-05-26T17:27:16Z")

</div>

> [@SomeOne](#):
>
> size() function should be the very first thing in setup()

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:

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

void draw() 
  {
  background(0);
  }

```

> **After \< Click here for code**
>
> ```auto
> /* 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:

> **[Processing in Java](https://happycoding.io/tutorials/java/processing-in-java)**
>
> Learn how to use Processing as a Java library.

> **[Readable Code](https://blog.pragmaticengineer.com/readable-code/)**
>
> Good code needs to meets two key requirements. First, it should be correct: when
> executing, it should produce the result that is expected. Second, it should be
> easy to read for other developers.
> 
> Coding is a social activity. Your code does not exist...

`:)`
