We are about to switch to a new forum software. Until then we have removed the registration on this forum.
In Processing 3.0 I get an error when I call loadPixels() after CreateGraphics(w,h).
Some code like this works fine in v2.2.1.
PGraphics pg;
public void setup() {
size(800, 600);
pg = createGraphics(width, height);
pg.loadPixels();
for (int i=0; i < pg.width*pg.height; i++)
pg.pixels[i] = i % 255;
pg.updatePixels();
background(pg);
}
But in version 3.0 returns me that:
Exception in thread "Animation Thread" java.lang.NullPointerException
at processing.awt.PGraphicsJava2D.getRaster(PGraphicsJava2D.java:2710)
at processing.awt.PGraphicsJava2D.loadPixels(PGraphicsJava2D.java:2734)
at myTemplate.setup(myTemplate.java:23)
at processing.core.PApplet.handleDraw(PApplet.java:2373)
at processing.awt.PSurfaceAWT$12.callDraw(PSurfaceAWT.java:1523)
at processing.core.PSurfaceNone$AnimationThread.run(PSurfaceNone.java:316)
I don't understand why my P3 version is calling any AWT code: processing.awt.PGraphicsJava2D.loadPixels
Any idea?
Answers
Great !!! Thank you very much!!!
The expression
pg.pixels[i] = i++ % 0400 | #000000
is quite cryptic for me @-) . What does it mean?i++ % 0400 | #000000
:++
there is the post incremental operator.%
is the modulo or remainder operator. Just to make sure i is always less than0400
: https://Processing.org/reference/modulo.html0400
=0x100
=256
.|
is the bitwise OR operator: https://Processing.org/reference/bitwiseOR.html#000000
=0xff000000
= PImage.ALPHA_MASK.Thanks!!!! ^:)^
I do hate it when he does this. All he needed to do was add pg.beginDraw() but instead he had to rewrite the entire thing and ends up raising more questions than he answers.
i think he's also introduced a bug....
Really thinks that, koogs? I do like this kind of response, it opens new ways for resolve a problem. I enjoy analyzing GoToLoop answers!!!