Skip to content

Second beginDraw / endDraw call clears PGraphics object when created w/ P2D #641

Closed
@processing-bot

Description

@processing-bot

Created by: rapatski

Description

Stumbled upon this just now - seems like beginDraw() / endDraw() clear the canvas of a PGraphics object when that object is created with the P2D renderer.

Expected Behavior

I expect the beginDraw() method not to change anything in the PGraphics object it's called on.

Current Behavior

Calling beginDraw() on a PGraphics object created with P2D and populated previously will clear it.

Steps to Reproduce

  1. Create PGraphics object with P2D renderer
  2. Draw into the PGraphics object, finish with endDraw()
  3. Call beginDraw() & endDraw() on the same object again
PGraphics pg;

void setup()
{
  size(500, 500, P2D);
  frameRate(60);
    
  //pg = createGraphics(width, height); // works as expected
  pg = createGraphics(width, height, P2D); // bug with beginDraw()/endDraw(), see below
  
  pg.beginDraw();
  pg.background(0, 255, 0); // green
  pg.endDraw();
  
  // this 'empties' the pg object in P2D mode
  pg.beginDraw();
  pg.endDraw();  
  
  background(255, 0, 0); // red
  
  // PG w/ P2D: renders transparent image,
  // PG w/ standard renderer: draws the original pg created in setup
  image(pg, 0, 0); 
}

Your Environment

  • Processing version: 3.5.4
  • Operating System and OS version: macOS Big Sur 11.4 (20F71)
  • Other information:

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions