micycle1 / PGS

Processing Geometry Suite
https://micycle1.github.io/PGS/
167 stars 13 forks source link

`PGS_Processing.slice()` returns nullpointer exception in `P2D` render mode #55

Closed mheesakkers closed 1 year ago

mheesakkers commented 2 years ago

Not sure if this is an issue, but I ran into a nullpointer exception when I was trying to slice a custom PShape using the P2D renderer. PShapes created in this renderer are for some reason of the type PShapeOpenGL which I think PGS can't handle, right?. Leaving the renderer option blank results in no errors.

micycle1 commented 2 years ago

Which version of PGS are you using? PGS 1.2.0+ behaves well with P2D. In fact I've just tried the slice example in P2D with the newest version and that's working fine.

In 1.2.0, output PShapes are now always created with a shape family of PATH (rather than GEOMETRY) to maximise compatibility with the P2D renderer.

mheesakkers commented 2 years ago

I'm running 1.2.0 but the problem only exists when you create a PShape with createShape(). Then a PShapeOpenGL is created it seems. And that PShapeOpenGL throws a null pointer in the slice method. The slice example works due to the PGS creation of a shape.

micycle1 commented 2 years ago

Can you share code?

This works in P2D for me:

var circle = createShape(ELLIPSE, width / 2, height / 2, 500, 500);
shape(PGS_Processing.slice(circle, new PVector(0, 0), new PVector(width, height)));
mheesakkers commented 2 years ago

Sure! Sorry took a while. But the difference lays in the way I create a PShape - I use createShape() with beginShape() and endShape(). The code below throws an error when you use the P2D renderer.

import micycle.pgs.*;

size(512, 512, P2D); // Remove P2D renderer and it works

PShape shape = createShape();
shape.beginShape();
for (int i = 0; i < 4; i++) {
        float angle = TWO_PI / 4 * i;
    float radius = 128;
    float x = width * 0.5 + sin(angle) * radius;
    float y = height * 0.5 + cos(angle) * radius;
    shape.vertex(x, y);
}
shape.endShape(CLOSE);

PShape slices = PGS_Processing.slice(shape, new PVector(0, 0), new PVector(width, height));
PGS_Conversion.setAllFillColor(slices, #333333);
PGS_Conversion.setAllStrokeColor(slices, #00ffff, 4);

shape(slices);