Selim Dincer
2018-11-08 19:35:00 UTC
Hey,
this morning I was doing something with the canvas control and got its size
wrong. It was way taller than I expected and I had an NPE somewhere in
NGCanvas but I didn't really understand what was wrong because nothing was
pointing to my code. I don't know how it behaves on linux, I was running
Windows 10.
A minimal example looks like following:
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.canvas.Canvas;
import javafx.scene.image.Image;
import javafx.scene.layout.BorderPane;
import javafx.stage.Stage;
public class CanvasTest extends Application {
@Override
public void start(Stage primaryStage) throws Exception {
Canvas canvas = new Canvas(128, 10000);
Image img = new
Image("Loading Image...");
canvas.getGraphicsContext2D().drawImage(img, 0, 0, 128, 128);
primaryStage.setScene(new Scene(new BorderPane(canvas)));
primaryStage.show();
}
}
The StackTrace of the NPE looks like following:
java.lang.NullPointerException
at com.sun.javafx.sg.prism.NGCanvas$RenderBuf.validate(NGCanvas.java:213)
at com.sun.javafx.sg.prism.NGCanvas.initCanvas(NGCanvas.java:640)
at com.sun.javafx.sg.prism.NGCanvas.renderContent(NGCanvas.java:603)
at com.sun.javafx.sg.prism.NGNode.doRender(NGNode.java:2053)
at com.sun.javafx.sg.prism.NGNode.render(NGNode.java:1945)
at com.sun.javafx.sg.prism.NGGroup.renderContent(NGGroup.java:235)
at com.sun.javafx.sg.prism.NGRegion.renderContent(NGRegion.java:576)
at com.sun.javafx.sg.prism.NGNode.doRender(NGNode.java:2053)
at com.sun.javafx.sg.prism.NGNode.render(NGNode.java:1945)
at com.sun.javafx.tk.quantum.ViewPainter.doPaint(ViewPainter.java:477)
at com.sun.javafx.tk.quantum.ViewPainter.paintImpl(ViewPainter.java:330)
at
com.sun.javafx.tk.quantum.PresentingPainter.run(PresentingPainter.java:91)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:308)
at com.sun.javafx.tk.RenderJob.run(RenderJob.java:58)
at
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at
com.sun.javafx.tk.quantum.QuantumRenderer$PipelineRunnable.run(QuantumRenderer.java:125)
at java.lang.Thread.run(Thread.java:748)
I guess you might have to make the canvas a little larger than that to
reproduce it on your system. I was creating the canvas as graphic of a
listcell and didn't realize that it was so large until I started debugging
(in this example the stage height indicates that something's wrong).
Maybe there should be a check with a more meaningful error message?
Thanks,
Selim
this morning I was doing something with the canvas control and got its size
wrong. It was way taller than I expected and I had an NPE somewhere in
NGCanvas but I didn't really understand what was wrong because nothing was
pointing to my code. I don't know how it behaves on linux, I was running
Windows 10.
A minimal example looks like following:
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.canvas.Canvas;
import javafx.scene.image.Image;
import javafx.scene.layout.BorderPane;
import javafx.stage.Stage;
public class CanvasTest extends Application {
@Override
public void start(Stage primaryStage) throws Exception {
Canvas canvas = new Canvas(128, 10000);
Image img = new
Image("Loading Image...");
canvas.getGraphicsContext2D().drawImage(img, 0, 0, 128, 128);
primaryStage.setScene(new Scene(new BorderPane(canvas)));
primaryStage.show();
}
}
The StackTrace of the NPE looks like following:
java.lang.NullPointerException
at com.sun.javafx.sg.prism.NGCanvas$RenderBuf.validate(NGCanvas.java:213)
at com.sun.javafx.sg.prism.NGCanvas.initCanvas(NGCanvas.java:640)
at com.sun.javafx.sg.prism.NGCanvas.renderContent(NGCanvas.java:603)
at com.sun.javafx.sg.prism.NGNode.doRender(NGNode.java:2053)
at com.sun.javafx.sg.prism.NGNode.render(NGNode.java:1945)
at com.sun.javafx.sg.prism.NGGroup.renderContent(NGGroup.java:235)
at com.sun.javafx.sg.prism.NGRegion.renderContent(NGRegion.java:576)
at com.sun.javafx.sg.prism.NGNode.doRender(NGNode.java:2053)
at com.sun.javafx.sg.prism.NGNode.render(NGNode.java:1945)
at com.sun.javafx.tk.quantum.ViewPainter.doPaint(ViewPainter.java:477)
at com.sun.javafx.tk.quantum.ViewPainter.paintImpl(ViewPainter.java:330)
at
com.sun.javafx.tk.quantum.PresentingPainter.run(PresentingPainter.java:91)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:308)
at com.sun.javafx.tk.RenderJob.run(RenderJob.java:58)
at
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at
com.sun.javafx.tk.quantum.QuantumRenderer$PipelineRunnable.run(QuantumRenderer.java:125)
at java.lang.Thread.run(Thread.java:748)
I guess you might have to make the canvas a little larger than that to
reproduce it on your system. I was creating the canvas as graphic of a
listcell and didn't realize that it was so large until I started debugging
(in this example the stage height indicates that something's wrong).
Maybe there should be a check with a more meaningful error message?
Thanks,
Selim