Bug 1264 : "Mysterious" internal crash if wrong code (empty PGraphics)
Last modified: 2009-06-03 12:29




Status:
RESOLVED
Resolution:
INVALID -
Priority:
P2
Severity:
normal

 

Reporter:
PhiLhoČ
Assigned To:
fry

Attachment Type Created Size Actions

Description:   Opened: 2009-06-03 02:37
Processing 1.0.1 on Windows
Code:
size(500, 500);
PImage img = loadImage("E:/Documents/Images/lines.gif");
PGraphics pg = createGraphics(img.width * 2, img.height * 2);
pg.image(img, 0, 0, img.width * 2, img.height * 2);

image(pg, 0, 0);

Runtime error:
Exception in thread "Animation Thread" java.lang.NullPointerException
at java.lang.System.arraycopy(Native Method)
at
sun.awt.image.IntegerInterleavedRaster.setDataElements(IntegerInterleavedRaster.java:412)
at processing.core.PGraphicsJava2D.updatePixels(PGraphicsJava2D.java:1661)
at processing.core.PGraphicsJava2D.imageImpl(PGraphicsJava2D.java:792)
at processing.core.PGraphics.image(PGraphics.java:2150)
at processing.core.PApplet.image(PApplet.java:7100)
at sketch_jun03a.setup(sketch_jun03a.java:21)
at processing.core.PApplet.handleDraw(PApplet.java:1383)
at processing.core.PApplet.run(PApplet.java:1311)
at java.lang.Thread.run(Thread.java:619)

I just forgot the pg.beginDraw() and pg.endDraw() around the pg.image().
This caused the updatePixels to happen without a previous loadPixel.
Not sure how to handle this gracefully in all cases, but maybe you can
detect the issue (null object) before the crash and show some friendlier
hint about what the problem can be. Might avoid beginners some puzzling... :-)
Additional Comment #1 From fry 2009-06-03 12:29
there's simply nothing to be done for this. users have to follow the
directions that say you can only draw inside a begin/end. otherwise we have
to add a check function to many dozen different functions, just to deal
with people who didn't read the reference. ;)