Closed Nancy-Salpepi closed 1 year ago
Reproduced in 1.5.0-dev.1 and master.
This was not a problem in 1.4.3. It's new in 1.5, and it's caused by the new scenery layout code.
Assigned to @jonathanolson with top priority.
Here's the stack trace from master:
I am also seeing that error message when I remove a row from the Alleles panel--For example: naturalSelection.labScreen.view.graphs.pedigreeNode.allelesPanel.earsRow.visibleProperty
More information, isolating the problem ... @jonathanolson let me know if you want to collaborate on this.
naturalSelection.labScreen.view.genes.furVisibleProperty
is one of the global Properties found in GenesVisibilityManager. It's used to globally show/hide all UI components that are related to a specific gene (in this case, fur).
In GeneVisibilityManager.js, the general listener for each Property is found in createGeneVisibleProperty
on line 59:
// Set the visibility of UI components related to the gene. unlink is not necessary.
property.link( visible => {
addMutationsPanel.setGeneVisible( gene, visible );
populationNode.setGeneVisible( gene, visible );
proportionsNode.setGeneVisible( gene, visible );
pedigreeNode.setGeneVisible( gene, visible );
} );
By commenting out the first 3 lines of that listener, I isolated the problem to pedigreeNode.setGeneVisible
:
// Set the visibility of UI components related to the gene. unlink is not necessary.
property.link( visible => {
// addMutationsPanel.setGeneVisible( gene, visible );
// populationNode.setGeneVisible( gene, visible );
// proportionsNode.setGeneVisible( gene, visible );
pedigreeNode.setGeneVisible( gene, visible );
} );
Drilling down, pedigreeNode.setGeneVisible
sets the visibility of a row in the Alleles panel, shown when the Pedigree radio button is selected.
In AllelesPanel.js:
setGeneVisible( gene, visible ) {
assert && assert( gene instanceof Gene, 'invalid gene' );
assert && assert( typeof visible === 'boolean', 'invalid visible' );
const row = _.find( this.rows, row => ( row.gene === gene ) );
assert && assert( row, `row not found for ${gene.name} gene` );
row.visible = visible;
}
If I comment out the last line of setGeneVisible
, the "stack size exceeded" exception does not occur. row.visible
is the visibility of a Row
, which is a subclass of HBox
defined in AllelesPanel.js.
As @Nancy-Salpepi reported in https://github.com/phetsims/natural-selection/issues/313#issuecomment-1180803621, directly setting visibility of any Row
in AllelsPanel.js also causes the exception. In the case of "fur", setting either naturalSelection.labScreen.view.genes.furVisibleProperty
or naturalSelection.labScreen.view.graphs.pedigreeNode.allelesPanel.furRow.visibleProperty
to false
causes the exception. Setting the latter does not require commenting out code like I did above.
So for the purposes of debugging, I recommend using:
naturalSelection.labScreen.view.graphs.pedigreeNode.allelesPanel.furRow.visibleProperty
I added this to AllelePanel constructor, to see if furRow.visibleProperty
is being toggle repeatedly. It is not -- the listener is called once, then the exception occurs.
furRow.visibleProperty.lazyLink( visible => {
console.log( `furRow.visible = ${visible}` );
} );
I started removing parts of AllelePanel's Row
class, to see if a specific UI component was triggering the problem. If I remove the Image used to represent the allele, the problem goes away. In AllelePanel.js, inner class AlleleNode extends HBox
:
const textNode = new Text( abbreviation, {
font: NaturalSelectionConstants.CHECKBOX_FONT,
maxWidth: 12 // determined empirically
} );
const imageNode = new Image( image, {
scale: 0.5 // determined empirically
} );
assert && assert( !options.children, 'AlleleNode sets children' );
- options.children = [ textNode, imageNode ];
+ options.children = [ textNode ];
That was quite a tricky interaction. It needed the 3-node-deep layout + a maxWidth/maxHeight. Because maxWidth is handled synchronously, it resulted in the scale being reduced on something that had a preferred width. Because the preferred width was larger than the maxWidth, it synchronously sized the content up slightly (violating the maxWidth). This would normally be fine, but this listener triggers BEFORE the additional layout code that would update the minimumWidth (and thus it would set the correct preferred width).
Long story short, it hit a loop where (a) every iteration, it was one level deeper in recursion due to maxWidth handling, so it crashed that way, and (b) it was shrinking the container (AllelesPanel) and growing the content iteratively in a loop.
By never setting our preferred width (from layout containers) above a maxWidth, this will (a) prevent this infinite loop and (b) allow correct behavior (since if we reduce the preferred size for that purpose, the maxWidth itself would scale up the node correctly later).
Can't reproduce with the commit above, and I've tested with snapshot testing to make sure there's no visible sim differences.
@pixelzoom can you test (and review?)
Wow, that sounds like fun :) Tested and working in master. Thanks for fixing!
@Nancy-Salpepi over to you for verification in master. If it looks OK, please label fixed-awaiting-deploy.
Removing the dev:phet-io label, since this was not techincal a PhET-iO problem. It just manifested in a PhET-iO content.
Looks good on my end as well!
To verify in https://github.com/phetsims/qa/issues/967, follow the steps in https://github.com/phetsims/natural-selection/issues/313#issue-1299183559.
Please close this issue if it verifies OK.
Looks good in 1.5.0-dev.5. Closing.
Test device MacBook Air (m1 chip)
Operating System macOS 12.4
Browser safari and chrome
Problem description For https://github.com/phetsims/qa/issues/818, when removing a gene from the Add Mutations panel on the Lab screen, an error message pops up in the console. It may also take 30-40 seconds for the checkbox to uncheck. The sim still works.
I didn't see this error when removing the fur gene on the Intro screen.
Steps to reproduce
naturalSelection.labScreen.view.genes.furVisibleProperty
and uncheck the checkboxVisuals