Skip to content

Commit

Permalink
add additional guards for isUpdatingLayout, #140
Browse files Browse the repository at this point in the history
  • Loading branch information
pixelzoom committed Jan 23, 2024
1 parent 07a9360 commit 5ce01d3
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions js/pointslope/view/PointSlopeEquationNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,9 @@ export default class PointSlopeEquationNode extends EquationNode {
}
);

// to prevent stack overflow, see https://github.com/phetsims/graphing-lines/issues/140#issuecomment-1904968755
let isUpdatingLayout = false;

// sync the controls and layout with the model
const lineObserver = ( line: Line ) => {

Expand All @@ -483,13 +486,16 @@ export default class PointSlopeEquationNode extends EquationNode {
updatingControls = false;

// Fully-interactive equations have a constant form, no need to update layout when line changes.
if ( !fullyInteractive ) { updateLayout( line ); }
if ( !fullyInteractive && !isUpdatingLayout ) {
isUpdatingLayout = true;
updateLayout( line );
isUpdatingLayout = false;
}
};
lineProperty.link( lineObserver ); // unlink in dispose

// If dynamic strings change, update the layout. xNode.boundsProperty and yNode.boundsProperty are RichText that
// are observing a StringProperty. slopeUndefinedStringProperty is used in this.updateLayout.
let isUpdatingLayout = false; // to prevent stack overflow, see https://github.com/phetsims/graphing-lines/issues/140#issuecomment-1904968755
const dynamicStringMultilink = Multilink.lazyMultilink(
[ xText.boundsProperty, yText.boundsProperty, GraphingLinesStrings.slopeUndefinedStringProperty ],
() => {
Expand All @@ -506,7 +512,11 @@ export default class PointSlopeEquationNode extends EquationNode {
if ( fullyInteractive ) {

// update layout once
updateLayout( lineProperty.value );
if ( !isUpdatingLayout ) {
isUpdatingLayout = true;
updateLayout( lineProperty.value );
isUpdatingLayout = false;
}

// add undefinedSlopeIndicator
const undefinedSlopeIndicator = new UndefinedSlopeIndicator( this.width, this.height );
Expand Down

0 comments on commit 5ce01d3

Please sign in to comment.