changeset 5712:4b5f33138e71

RT-34271 :Infinite loop in computing layout Reviewed by: kcr
author Martin Sladecek <martin.sladecek@oracle.com>
date Thu, 14 Nov 2013 14:19:21 +0100
parents 45d8a3cde4ec
children 09373222be64
files modules/graphics/src/main/java/javafx/scene/Parent.java
diffstat 1 files changed, 13 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/modules/graphics/src/main/java/javafx/scene/Parent.java	Thu Nov 14 13:12:43 2013 +0200
+++ b/modules/graphics/src/main/java/javafx/scene/Parent.java	Thu Nov 14 14:19:21 2013 +0100
@@ -1053,12 +1053,25 @@
 
     /**
      * Executes a top-down layout pass on the scene graph under this parent.
+     * 
+     * Calling this method while the Parent is doing layout is a no-op.
      */
     public final void layout() {
         switch(layoutFlag) {
             case CLEAN:
                 break;
             case NEEDS_LAYOUT:
+                if (performingLayout) {
+                    /* This code is here mainly to avoid infinite loops as layout() is public and the call might be (indirectly) invoked accidentally
+                     * while doing the layout.
+                     * One example might be an invocation from Group layout bounds recalculation
+                     *  (e.g. during the localToScene/localToParent calculation).
+                     * The layout bounds will thus return layout bounds that are "old" (i.e. before the layout changes, that are just being done), 
+                     * which is likely what the code would expect.
+                     * The changes will invalidate the layout bounds again however, so the layout bounds query after layout pass will return correct answer.
+                     */
+                    break;
+                }
                 performingLayout = true;
                 layoutChildren();
                 // Intended fall-through