javafx NullPointerException when rendering big image

javafx NullPointerException when rendering big image



I'm trying to render a .png Image using the GraphicsContext.drawImage(...) method under JavaFX 8. My code works perfectly fine for an image of size ~1000px x 2000px.
But unfortunately I need to render an image of size 7000px x 14000px. Loading this image works fine as well, but when calling the drawImage(image, 0, 0, canvas.getWidth(), canvas.getHeight()) method I get the following error output:


GraphicsContext.drawImage(...)


drawImage(image, 0, 0, canvas.getWidth(), canvas.getHeight())


java.lang.NullPointerException
at com.sun.prism.impl.BaseGraphics.drawTexture(BaseGraphics.java:389)
at com.sun.prism.impl.ps.BaseShaderGraphics.drawTexture(BaseShaderGraphics.java:139)
at com.sun.javafx.sg.prism.NGCanvas.handleRenderOp(NGCanvas.java:1228)
at com.sun.javafx.sg.prism.NGCanvas.renderStream(NGCanvas.java:997)
at com.sun.javafx.sg.prism.NGCanvas.renderContent(NGCanvas.java:578)
... more rendering stuff here
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:317)
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:745)



It doesn't make a difference if I try to resize the image while drawing to the canvas or if I try to render the whole image.



My guess is that the image size is simply too big to render, but I could'nt find any source to validate this and neither could I find anything to solve my problem.



I also made an analysis of the Java heap (with Eclipse Memory Analyzer) which showed an image size of approximately 376 MB.



So basically my question are:
1. Why is my program crashing? Is it because the image is too big?
2. If my image is too big, how can I increase the available space for Java? My machine has 8GB RAM and the graphics card has 1GB RAM, so an image of <400MB should not really be a problem.






Did you try increasing the heap size ?

– ItachiUchiha
May 5 '14 at 8:19






Yes, I tried it using 4GB. And I'm not getting a OutOfMemoryError, but a NullPointerException which also means that my program is still running after the Exception is thrown. It just can't render the canvas any longer.

– schauk11erd
May 5 '14 at 8:33


OutOfMemoryError


NullPointerException






Yes, I know that ! Its quite strange that you are getting a NullPointerException for a large image !

– ItachiUchiha
May 5 '14 at 8:35


NullPointerException






Might be related to a some bug tracker issues RT-36386, RT-36540, RT-32258. I guess you could report it at javafx-jira.kenai.com if none of the linked issues seem like duplicates (or their resolutions don't seem satisfactory). 7Kx14K is a really big image...

– jewelsea
May 5 '14 at 20:43







Related Oracle forum discussion may be useful. My guess is that either 8Kx8K or 4Kx4K images will work on your hardware/software combo, but larger images may not.

– jewelsea
May 5 '14 at 21:07





3 Answers
3



As somebody pointed in comments - only up tp 4k/8k textures will work for you. This is because JavaFX probably uses GPU to render images. Texture size limit is probably the limit of yout GPU or GPU drivers that can't handle bigger textures. It can't create so big texture so it returns null (and that explains the NullPointerException).



The only way to fix it is to avoid using so big textures or get better hardware to support bigger textures. Using software rendering (which may be really slow) may fix it by running java with the following parameters:


-Dprism.order=j2d



or


-Dprism.order=sw



But I'm not sure it's what you want to achieve.



I could solve it with the 2 VM-Arguments:


-Dprism.order=sw
-Xmx1024m



I needed both of them.



I solved it for me with VM-Arguments:



-Dprism.poolstats=true
-Dprism.maxvram=500m
-Dprism.order=sw
-Djavafx.animation.fullspeed=true


-Dprism.poolstats=true
-Dprism.maxvram=500m
-Dprism.order=sw
-Djavafx.animation.fullspeed=true



Thanks for contributing an answer to Stack Overflow!



But avoid



To learn more, see our tips on writing great answers.



Required, but never shown



Required, but never shown




By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

Edmonton

Crossroads (UK TV series)