Closed Nancy-Salpepi closed 1 year ago
I am able to reproduce the bug, and I can even see it when moving wire1 to index 4 (same page).
In IndexedNodeIO, when calling node.addChild() on that wireNode is causing an infinite loop sort of symptom.
Subject: [PATCH] Add documentation, see https://github.com/phetsims/chipper/issues/1369
---
Index: js/nodes/IndexedNodeIO.ts
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/js/nodes/IndexedNodeIO.ts b/js/nodes/IndexedNodeIO.ts
--- a/js/nodes/IndexedNodeIO.ts (revision 772149d66d6ad30f80ece0ade67b0b277b956421)
+++ b/js/nodes/IndexedNodeIO.ts (date 1676648345783)
@@ -83,7 +83,15 @@
const currentIndex = nodeParent.indexOfChild( node );
children[ currentIndex ] = children[ stateObject.index ];
children[ stateObject.index ] = node;
- nodeParent.setChildren( children );
+ console.log( 'setting children: ', children );
+ nodeParent.children = [];
+ children.forEach( ( child, i ) => {
+ console.log( 'start ' + i );
+ nodeParent.addChild( child );
+ console.log( 'end ' + i );
+ } );
+ // nodeParent.setChildren( children );
+ console.log( 'done' );
}
},
stateSchema: {
Commenting out this line of code avoids the problem, so there is some sort of cycle or problem in the carousel ManualConstraint layout:
Subject: [PATCH] Scroll to an item when its position in the carousel changes, see https://github.com/phetsims/studio/issues/296
---
Index: js/Carousel.ts
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/js/Carousel.ts b/js/Carousel.ts
--- a/js/Carousel.ts (revision 13065d19035b2e48279d4403bf074b0bb745964c)
+++ b/js/Carousel.ts (date 1676734648476)
@@ -420,7 +420,7 @@
windowProxy[ orientation.opposite.centerCoordinate ] = backgroundProxy[ orientation.opposite.centerCoordinate ];
previousProxy[ orientation.minSide ] = backgroundProxy[ orientation.minSide ];
nextProxy[ orientation.maxSide ] = backgroundProxy[ orientation.maxSide ];
- windowProxy[ orientation.centerCoordinate ] = backgroundProxy[ orientation.centerCoordinate ];
+ // windowProxy[ orientation.centerCoordinate ] = backgroundProxy[ orientation.centerCoordinate ];
} );
// Handle changing pages (or if the content changes)
This experiment shows there is an infinite loop in the ManualConstraint:
Subject: [PATCH] Scroll to an item when its position in the carousel changes, see https://github.com/phetsims/studio/issues/296
---
Index: js/Carousel.ts
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/js/Carousel.ts b/js/Carousel.ts
--- a/js/Carousel.ts (revision 13065d19035b2e48279d4403bf074b0bb745964c)
+++ b/js/Carousel.ts (date 1676734964725)
@@ -413,14 +413,22 @@
foregroundNode.rectBounds = bounds;
} );
+ let depth = 0;
// Top-level layout (based on background changes)
ManualConstraint.create( this, [ backgroundNode, windowNode, previousButton, nextButton ], ( backgroundProxy, windowProxy, previousProxy, nextProxy ) => {
- nextProxy[ orientation.opposite.centerCoordinate ] = backgroundProxy[ orientation.opposite.centerCoordinate ];
- previousProxy[ orientation.opposite.centerCoordinate ] = backgroundProxy[ orientation.opposite.centerCoordinate ];
- windowProxy[ orientation.opposite.centerCoordinate ] = backgroundProxy[ orientation.opposite.centerCoordinate ];
- previousProxy[ orientation.minSide ] = backgroundProxy[ orientation.minSide ];
- nextProxy[ orientation.maxSide ] = backgroundProxy[ orientation.maxSide ];
- windowProxy[ orientation.centerCoordinate ] = backgroundProxy[ orientation.centerCoordinate ];
+
+ depth++;
+ console.log( depth );
+ if ( depth < 5 ) {
+ nextProxy[ orientation.opposite.centerCoordinate ] = backgroundProxy[ orientation.opposite.centerCoordinate ];
+ previousProxy[ orientation.opposite.centerCoordinate ] = backgroundProxy[ orientation.opposite.centerCoordinate ];
+ windowProxy[ orientation.opposite.centerCoordinate ] = backgroundProxy[ orientation.opposite.centerCoordinate ];
+ previousProxy[ orientation.minSide ] = backgroundProxy[ orientation.minSide ];
+ nextProxy[ orientation.maxSide ] = backgroundProxy[ orientation.maxSide ];
+ windowProxy[ orientation.centerCoordinate ] = backgroundProxy[ orientation.centerCoordinate ];
+ }
+
+ depth--;
} );
// Handle changing pages (or if the content changes)
@jonathanolson and/or @marlitas may have helpful expertise here.
This also short circuits the infinite loop:
Subject: [PATCH] Scroll to an item when its position in the carousel changes, see https://github.com/phetsims/studio/issues/296
---
Index: js/Carousel.ts
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/js/Carousel.ts b/js/Carousel.ts
--- a/js/Carousel.ts (revision 13065d19035b2e48279d4403bf074b0bb745964c)
+++ b/js/Carousel.ts (date 1676736789473)
@@ -360,7 +360,7 @@
// Specify the local bounds in order to ensure centering. For full pages, this is not necessary since the scrollingNodeContainer
// already spans the full area. But for a partial page, this is necessary so the window will be centered.
- windowNode.localBounds = bounds;
+ // windowNode.localBounds = bounds;
} );
// Background - displays the carousel's fill color
This workaround works and shows a correct-looking layout, but hopefully we can find a better solution:
Subject: [PATCH] Scroll to an item when its position in the carousel changes, see https://github.com/phetsims/studio/issues/296
---
Index: js/Carousel.ts
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/js/Carousel.ts b/js/Carousel.ts
--- a/js/Carousel.ts (revision 13065d19035b2e48279d4403bf074b0bb745964c)
+++ b/js/Carousel.ts (date 1676737107949)
@@ -360,7 +360,9 @@
// Specify the local bounds in order to ensure centering. For full pages, this is not necessary since the scrollingNodeContainer
// already spans the full area. But for a partial page, this is necessary so the window will be centered.
- windowNode.localBounds = bounds;
+ setTimeout( () => {
+ windowNode.localBounds = bounds;
+ }, 0 );
} );
// Background - displays the carousel's fill color
@samreid feels that this issue warrants collaboration. We will circle back with @jonathanolson and @marlitas to set up some collaborative time to work on this.
Current patch from collaboration with @marlitas @zepumph @matthew-blackman and me:
@Nancy-Salpepi we think we solved it! Can you confirm on phettest?
I messaged Slack #dev-public:
Thanks to @marlitas @zepumph @matthew-blackman and me, Carousel got another significant improvement, which uses layout constraints more effectively and now a corner case no longer crashes. Details are in https://github.com/phetsims/circuit-construction-kit-common/issues/969. We tested several sims but not every sim exhaustively. Please test your use case and report any regressions.
This looks good in master 🎉.
Everything looks good here. Closing this issue.
Test device MacBook Air M1 chip
Operating System 13.1
Browser Safari and Chrome
Problem description For https://github.com/phetsims/qa/issues/900, if wireToolNode1 is moved to page 2 of the carousel and the sim is launched, it will not open and Studio will freeze. No errors appear in the console.
Steps to reproduce Method 1:
circuitConstructionKitDc.introScreen.view.circuitElementToolbox.carousel.items.wireToolNode1
and move it down to position 5.Method 2:
Visuals
https://user-images.githubusercontent.com/87318828/219674845-c26f37c4-bab9-4344-be60-2f366c490806.mp4