Most appropriate sub-area of Processing 4?
Core/Environment/Rendering
Processing version
4.5.2
Operating system
Linux (Unbuntu) and MacOS Tahoe
Bug description
I get a null pointer exception when I pass a PGraphics object to the background() method.
For some reason the PDE doesn't display the stack trace, I just see this:
NullPointerException
NullPointerException
Steps to reproduce this
The example code below reproduces the bug.
snippet
PGraphics g;
void setup() {
size(300, 300, P3D);
g = createGraphics(width, height, P2D);
g.beginDraw();
g.background(0, 255, 0);
g.endDraw();
}
void draw() {
background(g);
}
I am able to get a stack trace when I use the equivalent code in py5. I traced the problem to the PGraphics object's null pixels array.
One possible workaround is to insert a g.loadPixels() call after g.endDraw(). That fixes the problem. Another workaround is to get() a PImage object:
PGraphics g;
PImage img;
void setup() {
size(300, 300, P3D);
g = createGraphics(width, height, P2D);
g.beginDraw();
g.background(0, 255, 0);
g.endDraw();
img = g.get();
}
void draw() {
background(img);
}
Additional context
Either workaround suggests a solution. I'm happy to make a PR to fix this, you can assign it to me.
Would you like to work on the issue?
Yes, I’d like to help with this
Most appropriate sub-area of Processing 4?
Core/Environment/Rendering
Processing version
4.5.2
Operating system
Linux (Unbuntu) and MacOS Tahoe
Bug description
I get a null pointer exception when I pass a
PGraphicsobject to thebackground()method.For some reason the PDE doesn't display the stack trace, I just see this:
Steps to reproduce this
The example code below reproduces the bug.
snippet
I am able to get a stack trace when I use the equivalent code in py5. I traced the problem to the
PGraphicsobject's nullpixelsarray.One possible workaround is to insert a
g.loadPixels()call afterg.endDraw(). That fixes the problem. Another workaround is toget()aPImageobject:Additional context
Either workaround suggests a solution. I'm happy to make a PR to fix this, you can assign it to me.
Would you like to work on the issue?
Yes, I’d like to help with this