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 5ce01d3 commit ffdf960
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions js/slopeintercept/view/SlopeInterceptEquationNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,9 @@ export default class SlopeInterceptEquationNode 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 @@ -443,24 +446,34 @@ export default class SlopeInterceptEquationNode 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 ) {
updateLayout( line );
}
};
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.
const dynamicStringMultilink = Multilink.lazyMultilink(
//TODO https://github.com/phetsims/graphing-lines/issues/140 Adding xText.boundsProperty to dependencies fails with 'stack size exceeded'
//TODO https://github.com/phetsims/graphing-lines/issues/140 Adding xText.boundsProperty to dependencies fails with 'stack size exceeded', despite isUpdatingLayout guards
[ yText.boundsProperty, GraphingLinesStrings.slopeUndefinedStringProperty ],
() => updateLayout( lineProperty.value )
() => {
isUpdatingLayout = true;
updateLayout( lineProperty.value );
isUpdatingLayout = false;
}
);

// For fully-interactive equations ...
let undefinedSlopeUpdater: ( line: Line ) => void;
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 ffdf960

Please sign in to comment.