# PGraphics behaving unexpectedly

**URL:** https://discourse.processing.org/t/pgraphics-behaving-unexpectedly/18710
**Category:** Processing
**Created:** [March 16, 2020, 6:39pm UTC](https://discourse.processing.org/t/pgraphics-behaving-unexpectedly/18710 "2020-03-16T18:39:03Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![hamoid](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/hamoid/32/58_2.png) [@hamoid](https://discourse.processing.org/u/hamoid)
#### Post date: [March 16, 2020, 6:39pm UTC](https://discourse.processing.org/t/pgraphics-behaving-unexpectedly/18710/1 "2020-03-16T18:39:04Z")

</div>

Hi there,

This is no longer behaving as it used to. If I’m not too sleepy, this program should draw a black screen, but I see it magenta. If inside `draw()` I remove everything except `image(...)` then it’s black.

```auto
PGraphics pg;
void setup() {  
  size(800, 800, P2D);
  background(255, 0, 255);
  pg = createGraphics(1000, 1000, P3D);
  pg.beginDraw();
  pg.background(0);
  pg.endDraw();
}
void draw() {
  pg.beginDraw();
  //pg.stroke(random(10));
  //pg.blendMode(ADD);
  //pg.line(0, random(height), width, random(height));
  pg.endDraw();  
  image(pg, 0, 0);
}

```

I also tried this but same magenta result:

```auto
PGraphics pg;
void setup() {  
  size(800, 800, P2D);
  background(255, 0, 255);
}
void draw() {
  if (pg == null) {
    pg = createGraphics(1000, 1000, P3D);
    pg.beginDraw();
    pg.background(0);
    pg.endDraw();
  }

  pg.beginDraw();
  //pg.stroke(random(10));
  //pg.blendMode(ADD);
  //pg.line(0, random(height), width, random(height));
  pg.endDraw();  
  image(pg, 0, 0);
}

```

Maybe someone could try this program to see if the issue is my OS? On Processing 3.5.4.

---

<div class="post-metadata">

### Author: ![hamoid](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/hamoid/32/58_2.png) [@hamoid](https://discourse.processing.org/u/hamoid)
#### Post date: [March 16, 2020, 6:52pm UTC](https://discourse.processing.org/t/pgraphics-behaving-unexpectedly/18710/2 "2020-03-16T18:52:08Z")

</div>

Found an ugly workaround. I’m sad that old programs just stop working.

```auto
PGraphics pg;
void setup() {  
  size(800, 800, P2D);
  background(255, 0, 255);
  pg = createGraphics(1000, 1000, P3D);
}
void draw() {
  pg.beginDraw();
  if (frameCount == 2) {
    pg.background(200, 100, 50);
  }
  pg.stroke(random(10));
  pg.blendMode(ADD);
  pg.line(0, random(height), width, random(height));
  pg.blendMode(SUBTRACT);
  pg.line(random(pg.width), 0, random(pg.width), pg.height);
  pg.endDraw();  
  image(pg, 0, 0);
}

```

Screenshot with `if(frameCount == 1)` (PGraphics is transparent):

 ![2020-03-16-194822_800x800_scrot](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/2/29e4e705896a1f363f85abd8477a5c3800b54ad6.png)

Screenshot with `if(frameCount == 2)` (PGraphics is opaque):

 ![2020-03-16-194844_800x800_scrot](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/e/ea4d675b0ba16d3c0832b8401ccebcd3b2e4cb67.jpeg)

ps. I planned uploading one sketch per day from my collection, so here goes the first one:

> **[hamoid/Fun-Programming](https://github.com/hamoid/Fun-Programming/tree/master/processing/ideas/2018/08/panZoomSketch)**
>
> Code from the Fun Programming video episodes about creative coding, and my own random sketches - hamoid/Fun-Programming

---

<div class="post-metadata">

### Author: ![noel](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/noel/32/213_2.png) [@noel](https://discourse.processing.org/u/noel)
#### Post date: [March 16, 2020, 7:27pm UTC](https://discourse.processing.org/t/pgraphics-behaving-unexpectedly/18710/3 "2020-03-16T19:27:53Z")

</div>

> [@hamoid](#):
>
> Maybe someone could try this program to see if the issue is my OS? On Processing 3.5.4

Confirmed. Same thing here. The way until then will be

> pg.fill(0); pg.rect(0,0,width,height);

---

<div class="post-metadata">

### Author: ![hamoid](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/hamoid/32/58_2.png) [@hamoid](https://discourse.processing.org/u/hamoid)
#### Post date: [March 16, 2020, 8:03pm UTC](https://discourse.processing.org/t/pgraphics-behaving-unexpectedly/18710/4 "2020-03-16T20:03:55Z")

</div>

I tried the approach you suggest but doesn’t work for me. The background is still transparent.

---

<div class="post-metadata">

### Author: ![noel](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/noel/32/213_2.png) [@noel](https://discourse.processing.org/u/noel)
#### Post date: [March 16, 2020, 8:54pm UTC](https://discourse.processing.org/t/pgraphics-behaving-unexpectedly/18710/5 "2020-03-16T20:54:15Z")

</div>

> [@hamoid](#):
>
> doesn’t work for me

True, sorry. I forgot that I changed PGraphics from P3D to default at the same time…

---

<div class="post-metadata">

### Author: ![noel](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/noel/32/213_2.png) [@noel](https://discourse.processing.org/u/noel)
#### Post date: [March 16, 2020, 9:20pm UTC](https://discourse.processing.org/t/pgraphics-behaving-unexpectedly/18710/6 "2020-03-16T21:20:36Z")

</div>

> [@hamoid](#):
>
> so here goes the first one:

Very nice!  
Interesting that if you put the class in the first tab, you get a size error. Setup() has to be in the first tab.

---

<div class="post-metadata">

### Author: ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)
#### Post date: [March 25, 2020, 1:02am UTC](https://discourse.processing.org/t/pgraphics-behaving-unexpectedly/18710/7 "2020-03-25T01:02:14Z")

</div>

@hamoid On 3.4 (MacOS) I can confirm that your top post sketches 1 and 2 both show magenta for a single frame, then show blank from then on. So something changed since 3.4.

Have you opened an issue?

- [https://github.com/processing/processing/issues](https://github.com/processing/processing/issues)
