PGraphics freezing when rendering to second PGraphics

I have a piece of code that requires two offscreen buffers. When i draw the first buffer into the second one with image(), the first buffer “freezes”.

I draw both graphics to the window in main,

void draw() {
  updateBuffer(buffers[0], buffers[1]);

  image(buffers[0], 0, 0);
  image(buffers[1], width/2, 0);
}

And they both draw as they should.

However when i add

  buffers[1].beginDraw(); 
  buffers[1].image(buffers[0], 0, 0); // Problem
  buffers[1].endDraw();

the first buffer “freezes” when i draw it in the window, however it still displays it’s updates inside the second buffer.

Interestingly enough, adding an empty beginDraw(), endDraw() fixes the problem.

  buffers[1].beginDraw(); 
  buffers[1].image(buffers[0], 0, 0); // Problem
  buffers[1].endDraw();
  buffers[0].beginDraw();
  buffers[0].endDraw();

Full snippet displaying the problem

PGraphics[] buffers = new PGraphics[2];

void setup() {
  size(1200, 600, P2D);

  for (int i = 0; i < 2; ++i) {
    buffers[i] = createGraphics(width/2, height);
    buffers[i].beginDraw();
    buffers[i].background(0);
    buffers[i].fill(i*255, 255 - i*255, 0);
    buffers[i].endDraw();
  }
}

void draw() {
  buffers[0].beginDraw();
  buffers[0].background(0);
  buffers[0].ellipse(frameCount*4%width/2, height/2, 10, 10);
  buffers[0].endDraw();

  buffers[1].beginDraw();
  buffers[1].background(0);
  buffers[1].ellipse(frameCount*4%width/2, height/2, 10, 10);

  //Uncomment this to cause buffers[0] to freeze
  //buffers[1].image(buffers[0], 0, 0); 
  buffers[1].endDraw();

  //Uncomment this to solve the buffers[0] freeze
  //buffers[0].beginDraw();
  //buffers[0].endDraw();

  image(buffers[0], 0, 0);
  image(buffers[1], width/2, 0);
}

Hello @lack_ofa_better_name ,

My exploration of this:

Click here to see code!
PGraphics[] buffers = new PGraphics[2];

void setup() 
  {
  size(600, 300, P2D);

  for (int i = 0; i < 2; ++i) 
    {
    buffers[i] = createGraphics(width/2, height, P2D); // Added P2D
    buffers[i].beginDraw();
    buffers[i].background(0);
    buffers[i].fill(i*255, 255 - i*255, 0);
    buffers[i].endDraw();
    }
  }

void draw() 
  {
  buffers[0].beginDraw();
  buffers[0].background(0);
  buffers[0].textAlign(CENTER, CENTER);
  buffers[0].textSize(96);
  buffers[0].text(frameCount, width/4, height/2);
  buffers[0].endDraw();
  
  image(buffers[0], 0, 0);

  buffers[1].beginDraw();
  buffers[1].background(0);
  buffers[1].image(buffers[0], 0, 0); 
  buffers[1].textAlign(CENTER, CENTER);
  buffers[1].textSize(48);
  buffers[1].text(frameCount, width/4, height/4);
  buffers[1].endDraw();

  image(buffers[1], width/2, 0);
  }
  
  void mousePressed() 
  {
  noLoop();
  }

void mouseReleased() 
  {
  loop();
  }

I modified this:

buffers[i] = createGraphics(width/2, height, P2D); // Added P2D

That was fun!

:)