JDK-8126604 : snapshot throws IllegalArgumentException if scene or node bounds is empty
  • Type: Bug
  • Component: javafx
  • Sub-Component: graphics
  • Affected Version: 7u6
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • Submitted: 2012-05-26
  • Updated: 2015-06-17
  • Resolved: 2012-05-29
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.
JDK 7
7u6Fixed
Related Reports
Relates :  
Description
The following code which takes a snapshot of an empty scene will throw an exception. A similar exception is thrown for a node with an empty bounds.

    Scene s = new Scene(new Group());
    s.snapshot(null);

Image dimensions must be > 0
java.lang.IllegalArgumentException: Image dimensions must be > 0
        at com.sun.prism.Image.<init>(Image.java:135)
        at com.sun.prism.Image.<init>(Image.java:118)
        at com.sun.prism.Image.fromByteBgraPreData(Image.java:44)
        at com.sun.javafx.tk.quantum.QuantumToolkit.createPlatformImage(QuantumToolkit.java:1312)
        at javafx.scene.image.Image.<init>(Image.java:662)
        at javafx.scene.image.WritableImage.<init>(WritableImage.java:70)
        at javafx.scene.Scene.doSnapshot(Scene.java:1110)
        at javafx.scene.Scene.doSnapshot(Scene.java:1167)
        at javafx.scene.Scene.snapshot(Scene.java:1237)

Comments
verified in b14
25-06-2012

http://jfxsrc.us.oracle.com/javafx/2.2/scrum/graphics/rt/rev/6fb22b665cf6 A unit test will be included as part of RT-21571
29-05-2012

The best solution is to clamp the lower range of width and height to 1, so that a Snapshot of an empty scene or node will produce a 1x1 image filled with the bg color. Here is the patch: diff --git a/javafx-ui-common/src/javafx/scene/Scene.java b/javafx-ui-common/src/javafx/scene/Scene.java --- a/javafx-ui-common/src/javafx/scene/Scene.java +++ b/javafx-ui-common/src/javafx/scene/Scene.java @@ -1104,8 +1104,8 @@ int yMin = (int)Math.floor(y); int xMax = (int)Math.ceil(x + w); int yMax = (int)Math.ceil(y + h); - int width = xMax - xMin; - int height = yMax - yMin; + int width = Math.max(xMax - xMin, 1); + int height = Math.max(yMax - yMin, 1); if (wimg == null) { wimg = new WritableImage(width, height); } else {
26-05-2012