Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NullPointerException when calling save() after surface.setSize() in P2D #5840

Open
blakej11 opened this issue Apr 17, 2019 · 1 comment
Open

Comments

@blakej11
Copy link

Description

A call to save() following a call to surface.setsize() gives a NullPointerException when using the P2D browser.

Expected Behavior

Using the default renderer yields the expected results. Looking at the code sample below, if I comment out the ", P2D" in the call to size() inside settings(), I get a file called "after.png" with a nicely centered circle; and if I also uncomment the call to save("before.png"), I get another file with a correctly off-center circle.

Current Behavior

Using the P2D renderer, the call to save("after.png") gives the following errors:

java.lang.NullPointerException
at java.awt.image.BufferedImage.setRGB(BufferedImage.java:1058)
at processing.core.PImage.saveImageIO(PImage.java:3229)
at processing.core.PImage.save(PImage.java:3406)
at processing.core.PGraphics.save(PGraphics.java:8399)
at processing.opengl.PGraphicsOpenGL.saveImpl(PGraphicsOpenGL.java:762)
at processing.opengl.PGraphicsOpenGL.save(PGraphicsOpenGL.java:5573)
at processing.core.PApplet.save(PApplet.java:3933)
at e45.draw(e45.java:31)
at processing.core.PApplet.handleDraw(PApplet.java:2475)
at processing.opengl.PSurfaceJOGL$DrawListener.display(PSurfaceJOGL.java:866)
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)
Error while saving image.
java.io.IOException: image save failed.
at processing.core.PImage.saveImageIO(PImage.java:3275)
at processing.core.PImage.save(PImage.java:3406)
at processing.core.PGraphics.save(PGraphics.java:8399)
at processing.opengl.PGraphicsOpenGL.saveImpl(PGraphicsOpenGL.java:762)
at processing.opengl.PGraphicsOpenGL.save(PGraphicsOpenGL.java:5573)
at processing.core.PApplet.save(PApplet.java:3933)
at e45.draw(e45.java:31)
at processing.core.PApplet.handleDraw(PApplet.java:2475)
at processing.opengl.PSurfaceJOGL$DrawListener.display(PSurfaceJOGL.java:866)
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)

Interestingly enough, if I uncomment the call to save("before.png") while still using the P2D renderer, it no longer crashes, and it creates a correct-looking "before.png"; but "after.png" looks like it has been drawn on an incorrectly-sized window:
after

Steps to Reproduce

Here's a simplified version of my code that reproduces the problem:

void settings() {
  size(768, 512, P2D);
}

void setup() {
  background(0);
  fill(0);
  stroke(255);
  ellipse(256, 256, 128, 128);
}

void draw() {
  // save("before.png");
  surface.setSize(512, 512);
  save("after.png");
  exit();
}

Your Environment

  • Processing version: 3.5.3
  • Operating System and OS version: MacOS 10.13.6
  • Other information:

Possible Causes / Solutions

@jeremydouglass
Copy link
Contributor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants