JDK-8089835 : [Canvas] NullPointerException when viewing large Canvas in ScrollPane
  • Type: Bug
  • Component: javafx
  • Sub-Component: graphics
  • Affected Version: 8u20
  • Priority: P4
  • Status: Open
  • Resolution: Unresolved
  • Submitted: 2014-01-22
  • Updated: 2020-10-05
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
tbdUnresolved
Description
When I create a large Canvas and put it into a ScollPane I get a NullPointerException as soon as the program starts:

java.lang.NullPointerException
	at com.sun.javafx.sg.prism.NGCanvas$RenderBuf.validate(NGCanvas.java:199)
	at com.sun.javafx.sg.prism.NGCanvas.initCanvas(NGCanvas.java:598)
	at com.sun.javafx.sg.prism.NGCanvas.renderContent(NGCanvas.java:575)
	at com.sun.javafx.sg.prism.NGNode.doRender(NGNode.java:2043)
	at com.sun.javafx.sg.prism.NGNode.render(NGNode.java:1951)
	at com.sun.javafx.sg.prism.NGGroup.renderContent(NGGroup.java:225)
	at com.sun.javafx.sg.prism.NGRegion.renderContent(NGRegion.java:575)
	at com.sun.javafx.sg.prism.NGNode.doRender(NGNode.java:2043)
	at com.sun.javafx.sg.prism.NGNode.render(NGNode.java:1951)
	at com.sun.javafx.sg.prism.NGGroup.renderContent(NGGroup.java:225)
	at com.sun.javafx.sg.prism.NGRegion.renderContent(NGRegion.java:575)
	at com.sun.javafx.sg.prism.NGNode.renderForClip(NGNode.java:2282)
	at com.sun.javafx.sg.prism.NGNode.renderRectClip(NGNode.java:2176)
	at com.sun.javafx.sg.prism.NGNode.renderClip(NGNode.java:2202)
	at com.sun.javafx.sg.prism.CacheFilter.impl_renderNodeToCache(CacheFilter.java:655)
	at com.sun.javafx.sg.prism.CacheFilter.render(CacheFilter.java:561)
	at com.sun.javafx.sg.prism.NGNode.renderCached(NGNode.java:2346)
	at com.sun.javafx.sg.prism.NGNode.doRender(NGNode.java:2034)
	at com.sun.javafx.sg.prism.NGNode.render(NGNode.java:1951)
	at com.sun.javafx.sg.prism.NGGroup.renderContent(NGGroup.java:225)
	at com.sun.javafx.sg.prism.NGRegion.renderContent(NGRegion.java:575)
	at com.sun.javafx.sg.prism.NGNode.doRender(NGNode.java:2043)
	at com.sun.javafx.sg.prism.NGNode.render(NGNode.java:1951)
	at com.sun.javafx.tk.quantum.ViewPainter.doPaint(ViewPainter.java:469)
	at com.sun.javafx.tk.quantum.ViewPainter.paintImpl(ViewPainter.java:324)
	at com.sun.javafx.tk.quantum.PresentingPainter.run(PresentingPainter.java:89)
	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:129)
	at java.lang.Thread.run(Thread.java:744)


Sample Code:

package application;

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.canvas.Canvas;
import javafx.scene.control.ScrollPane;
import javafx.stage.Stage;

public class NPELargeCanvas extends Application
{
	@Override
	public void start(final Stage primaryStage)
	{
		final double x = 2500;
		final double y = 10000;
		final Canvas canvas = new Canvas(x,y);

		final ScrollPane pane = new ScrollPane();
		pane.setContent(canvas);

		primaryStage.setScene(new Scene(pane));
		primaryStage.show();
	}

	public static void main(final String[] args)
	{
		launch(args);
	}

}


Steps to Reproduce:
1) Just launch the program
Comments
_I don't have a problem with "try it and see if it works"_ - neither would I, given a way to being able to detect the not-working at runtime: PresentingPainter.run logs any exception and after that the app seems to be just blocked. See a recent question at SO https://stackoverflow.com/q/64207627/203657
05-10-2020

I'd like to emphasize on what Steve said, a more accurate error message would be sufficient. But getting a NPE when you allocate resources is just weird, I really thought there was a deeper desing flaw in javafx. However a message �� la "Insufficient memory for this texture size" and I would immeditaley have understood that something in my assumptions about my program is wrong.
28-01-2014

I don't have a problem with "try it and see if it works". Graphics cards are different and some things may work on certain cards. We are just asking for a better error message (if possible) when it fails.
27-01-2014

The problem is that we don't advertise any maximum size and "try it and see if it works" isn't a very good way to inform the developer. Also, the maximum sizes of textures may not be the same on all platforms so a program may run fine on a beefy desktop and then fail on embedded or an older laptop. We should probably pick a decent size we will guarantee and work on tiling to support it if a given platform does not support textures that large - or provide an internal way to back off to the software pipeline for larger textures even if the main pipeline is hw-based.
25-01-2014

Sounds reasonable, Jim? I'm not sure whether we have enough information at the time that the creation of the underlying native graphics resource fails as to the exact cause, but we could at least not throw and NPE.
24-01-2014

I could understand if you will not support such a large Canvas, I didn't really think about the needed memory for such large textures. I am going to solve my problem in a different way, but if you do not fix it it would still be nice if instead of a NullPointerException a more usefull error message was generated, e.g. Canvas to big for memory or something like that.
24-01-2014

It is likely that we simply do not support a canvas this big. It is likely that we will close this as 'won't fix'.
23-01-2014

I forgot to say that the desired size of the canvas should be 100 times larger than this, i.e. roughly 3000x1250000 pixels in size
22-01-2014