processing / processing-android

Processing mode and core library to create Android apps with Processing
http://android.processing.org
779 stars 293 forks source link

Android Mode PShape Vertex Default Renderer Error #701

Closed spacemanstan closed 2 years ago

spacemanstan commented 2 years ago

I believe the default renderer in Android mode has a bug affecting PShapes drawn using vertices.

The issue only seems to occur when trying to declare a PShape object, and drawing to that object using vertices. The error can be bypassed by drawing the shape in the main Draw() loop repeatedly, however I believe that removes the advantage of using a PShape. The error message (partially) thrown is

FATAL EXCEPTION: Animation Thread Process: processing.test.pshapetest, PID: 4730 java.lang.ArrayIndexOutOfBoundsException: src.length=2 srcPos=0 dst.length=37 dstPos=0 length=37 at java.lang.System.arraycopy(Native Method) at processing.core.PGraphics.vertex(PGraphics.java:1427)

However if you change the renderer to P2D the error vanishes. I didn't paste the entire error but what stood out to me, which is the arraycopy and vertex messages. I tried drawing the shapes in many different ways but P2D appears the only way to draw vertex shapes so far from my small amount of experimenting.

This code will throw the error message I quoted above:

PShape test;
float dim;
PVector testPos;

void setup() {
  fullScreen();
  orientation(PORTRAIT);

  dim = width/10;
  testPos = new PVector(width/2, height*2/3);

  test = createShape();

  test.beginShape();

  test.noStroke();
  test.fill(255);

  test.vertex(0, -2*dim);
  test.vertex(-dim, dim);
  test.vertex(dim, dim);

  test.endShape(CLOSE);
}

void draw() {
  background(0);

  pushMatrix();

  translate(testPos.x, testPos.y);

  shape(test);

  popMatrix();
}

but if you change fullScreen(); to fullScreen(P2D); it will compile and run fine.

I made a reddit post about it and tried running the code that was suggested in a thread I was linked to in the reddit post I made and had similar results.

I think this may be a bug with the default renderer.

codeanticode commented 2 years ago

@spacemanstan thanks for posting this issue, I can confirm that affects the default renderer only on Android, not in the Java mode. I will look into it.