changeset 2813:57f5d847140b

RT-28797: Fixed NPE when picking node clipped by a node with pickOnBounds set to true.
author Pavel Safrata
date Wed, 06 Mar 2013 08:10:35 +0000
parents 14df3baed0f8
children dd17e3699d72
files javafx-ui-common/src/javafx/scene/Node.java javafx-ui-common/test/unit/javafx/scene/PickAndContainsTest.java
diffstat 2 files changed, 38 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/javafx-ui-common/src/javafx/scene/Node.java	Tue Mar 05 23:57:09 2013 -0800
+++ b/javafx-ui-common/src/javafx/scene/Node.java	Wed Mar 06 08:10:35 2013 +0000
@@ -4366,7 +4366,9 @@
         double boundsDistance = impl_intersectsBounds(pickRay);
         if (!Double.isNaN(boundsDistance)) {
             if (isPickOnBounds()) {
-                pickResult.offer(this, boundsDistance, PickResultChooser.computePoint(pickRay, boundsDistance));
+                if (pickResult != null) {
+                    pickResult.offer(this, boundsDistance, PickResultChooser.computePoint(pickRay, boundsDistance));
+                }
                 return true;
             } else {
                 return impl_computeIntersects(pickRay, pickResult);
--- a/javafx-ui-common/test/unit/javafx/scene/PickAndContainsTest.java	Tue Mar 05 23:57:09 2013 -0800
+++ b/javafx-ui-common/test/unit/javafx/scene/PickAndContainsTest.java	Wed Mar 06 08:10:35 2013 +0000
@@ -163,6 +163,41 @@
     }
 
     @Test
+    public void testScenePickingGroupAndClipWithPickOnBounds() {
+        Group grp;
+        Rectangle r0;
+        Rectangle r1;
+        Rectangle r2;
+        Group root = new Group();
+        root.getChildren().addAll(r0 = new Rectangle(100, 100, 40, 20),
+                                grp = new Group(r1 = new Rectangle(0,0,40,20),
+                                                r2 = new Rectangle(200,200,40,20))
+                                );
+        Scene scene = new Scene(root);
+        r1.setId("Rect 1");
+        r1.setClip(new Circle(20,10,10));
+        r2.setId("Rect 2");
+        grp.setClip(new Circle(120,120,120));
+        grp.getClip().setPickOnBounds(true);
+
+        int pickX = 38;
+        int pickY = 18;
+        assertNull(scene.test_pick(pickX, pickY));
+        assertFalse(grp.contains(pickX, pickY));
+        assertFalse(r0.contains(pickX, pickY));
+        assertFalse(r1.contains(pickX, pickY));
+        assertFalse(r2.contains(pickX, pickY));
+
+        pickX = 230;
+        pickY = 215;
+        assertSame(r2, scene.test_pick(pickX, pickY));
+
+        pickX = 120;
+        pickY = 110;
+        assertSame(r0, scene.test_pick(pickX, pickY));
+    }
+
+    @Test
     public void testSceneGroupPickOnBounds() {
         Group grp;
         Rectangle r0;