无论出于什么原因,当我运行程序时,我得到一个NullPointerException。这是崩溃日志:
java.lang.NullPointerException
at processing.awt.PGraphicsJava2D.getRaster(PGraphicsJava2D.java:2727)
at processing.awt.PGraphicsJava2D.loadPixels(PGraphicsJava2D.java:2751)
at processing.opengl.PGraphicsOpenGL.initCache(PGraphicsOpenGL.java:6471)
at processing.opengl.PGraphicsOpenGL.getTexture(PGraphicsOpenGL.java:6424)
at processing.opengl.PGraphicsOpenGL$TexCache.getTexture(PGraphicsOpenGL.java:7464)
at processing.opengl.PGraphicsOpenGL.flushPolys(PGraphicsOpenGL.java:2430)
at processing.opengl.PGraphicsOpenGL.flush(PGraphicsOpenGL.java:2371)
at processing.opengl.PGraphicsOpenGL.endDraw(PGraphicsOpenGL.java:1540)
at processing.core.PApplet.handleDraw(PApplet.java:2436)
at processing.opengl.PSurfaceJOGL$DrawListener.display(PSurfaceJOGL.java:884)
at jogamp.opengl.GLDrawableHelper.displayImpl(GLDrawableHelper.java:692)
at jogamp.opengl.GLDrawableHelper.display(GLDrawableHelper.java:674)
at jogamp.opengl.GLAutoDrawableBase$2.run(GLAutoDrawableBase.java:443)
at jogamp.opengl.GLDrawableHelper.invokeGLImpl(GLDrawableHelper.java:1293)
at jogamp.opengl.GLDrawableHelper.invokeGL(GLDrawableHelper.java:1147)
at com.jogamp.newt.opengl.GLWindow.display(GLWindow.java:759)
at com.jogamp.opengl.util.AWTAnimatorImpl.display(AWTAnimatorImpl.java:81)
at com.jogamp.opengl.util.AnimatorBase.display(AnimatorBase.java:452)
at com.jogamp.opengl.util.FPSAnimator$MainTask.run(FPSAnimator.java:178)
at java.util.TimerThread.mainLoop(Timer.java:555)
at java.util.TimerThread.run(Timer.java:505)
Could not run the sketch (Target VM failed to initialize).
For more information, read revisions.txt and Help ? Troubleshooting.
仅当我使用P2D / P3D时才会发生这种情况。 JAVA2D工作得很好,但是我想使用P2D,因为否则程序就像滞后一样。
答案 0 :(得分:0)
请仔细检查您是否正在为草图和PGraphics使用显式渲染器,尤其是对于GL渲染器(例如P2D
/ P3D
)。
例如:
PGraphics buffer;
void setup(){
size(400,400,P3D);
buffer = createGraphics(width,height,P3D);
buffer.beginDraw();
buffer.background(0);
buffer.sphereDetail(4);
buffer.noFill();
buffer.endDraw();
}
void draw(){
float size = map(sin(frameCount * .01),-1.0,1.0,0.0,100.0);
buffer.beginDraw();
buffer.stroke(255,size * 0.5);
buffer.translate(mouseX,mouseY,0);
buffer.rotate(frameCount * 0.01,0.5,0.5,1.0);
buffer.sphere(size);
buffer.endDraw();
image(buffer,0,0);
}