PGraphics ConcurrentModificationException when using P3D/OpenGL

I'm running into some odd problems with PGraphics with Processing 2.1, but am posting here before submitting a bug report. The following code works fine with the default renderer, but throws a ConcurrentModificationException when using P3D or OpenGL. I also note that without the vertex portion of the code, there is no error. I'm not sure if it that means that's the cause, or it just needed enough going on to break things.

PGraphics pg;

void setup() {
  size(300, 300, OPENGL);

  int i = 0;
  while (true) {
    println(i);
    pg = createGraphics(width, height, OPENGL);
    pg.beginDraw();
    pg.background(0);
    pg.beginShape();
    pg.stroke(255);
    for (int j=0; j<10; j++) {
      pg.vertex(random(width), random(height));
    }
    pg.endShape();
    pg.endDraw();
    i += 1;
  }
}

Has anyone else had these problems? Any suggestions?

Answers

  • edited November 2013

    Further tests: any shapes drawn like above cause the error, not just beginShape(). This also occurs when running in the draw() loop.

    PGraphics pg;
    
    void setup() {
      size(300, 300, P3D);
    }
    
    void draw() {
      println(frameCount);
      pg = createGraphics(width, height, P3D);
      pg.beginDraw();
      pg.background(0);
      pg.stroke(255);
      for (int j=0; j<10; j++) {
        pg.point(100, 100);
      }
      pg.endDraw();
    }
    

    But it appears that creating the PGraphics once in the setup and using pg.clear() might be a solution.

Sign In or Register to comment.