We are about to switch to a new forum software. Until then we have removed the registration on this forum.
In the draw, if i disable image(d.pg, 0, 0);
the sketch runs fine.
Else i get:
Exception in thread "Animation Thread" java.lang.NullPointerException
at java.lang.System.arraycopy(Native Method)
at sun.awt.image.IntegerInterleavedRaster.setDataElements(IntegerInterleavedRaster.java:425)
at processing.core.PGraphicsJava2D$ImageCache.update(PGraphicsJava2D.java:1484)
at processing.core.PGraphicsJava2D.imageImpl(PGraphicsJava2D.java:1301)
at processing.core.PGraphics.image(PGraphics.java:3575)
at processing.core.PApplet.image(PApplet.java:12761)
at MyProcessingSketch.draw(MyProcessingSketch.java:43)
at processing.core.PApplet.handleDraw(PApplet.java:2384)
at processing.core.PGraphicsJava2D.requestDraw(PGraphicsJava2D.java:240)
at processing.core.PApplet.run(PApplet.java:2254)
at java.lang.Thread.run(Thread.java:695)
Can someone help?
import processing.core.*;
public class MyProcessingSketch extends PApplet {
int id;
Data d;
public static void main(String args[]) {
PApplet.main(new String[] { "MyProcessingSketch", "0" });
PApplet.main(new String[] { "MyProcessingSketch", "1" });
}
public void init() {
id = parseInt(args[args.length - 1]);
PApplet.println("init:"+id);
d = Data.getInstance();
super.init();
}
public void setup() {
size(800, 600);
}
public void draw() {
background(0, 255, 0);
if (id == 0) {
d.createGraphics(this);
image(d.pg, 0, 0);
}
else {
if(d.pg != null) {
// disable the next line and the sketch
// runs fine
image(d.pg, 0, 0);
}
}
fill(255, 0, 0);
text(frameRate, 20, 40);
}
}
import processing.core.PApplet;
import processing.core.PGraphics;
public enum Data {
INSTANCE;
PGraphics pg;
public static Data getInstance() {
return INSTANCE;
}
void createGraphics(PApplet p) {
if (pg == null);
pg = p.createGraphics(p.width, p.height);
pg.beginDraw();
pg.background(255, 0, 0);
pg.line(0, 0, p.width, p.height);
pg.endDraw();
}
}
Answers
Here a update: It works now, and framerate is high in both. But the shared image drawn is only fast in one.
Data.java