phetsims / beers-law-lab

"Beer's Law Lab" is an educational simulation in HTML5, by PhET Interactive Simulations.
http://phet.colorado.edu/en/simulation/beers-law-lab
GNU General Public License v3.0
2 stars 9 forks source link

spurious piece of solute appears after launching in Studio #247

Closed pixelzoom closed 1 year ago

pixelzoom commented 4 years ago

In https://github.com/phetsims/beers-law-lab/issues/244#issuecomment-593631064, @samreid reported:

When shaking solute out in studio, and pressing the "launch" button, an extra spurious piece of solute appears after launching. May be a pre-existing problem and/or tracked in another issue?

We'll look at this as part of PhET-iO redesign #230.

pixelzoom commented 4 years ago

To reproduce:

  1. Start the sim in Studio
  2. Go to Concentration screen
  3. Move the shaker
  4. Press the "Launch" button in Studio
  5. The sim opens in a new tab. Note that 1 solute particle will be dispensed from the shaker.

The relevant Property is dispensingProperty in Shaker, and it's set in step:

  // @public Sets the dispensing rate if the shaker is moving.
  step() {
    if ( this.visibleProperty.get() && !this.emptyProperty.get() ) {
      if ( this.previousPosition.equals( this.positionProperty.get() ) ) {
        this.dispensingRateProperty.set( 0 ); // shaker is not moving, don't dispense anything
      }
      else {
        this.dispensingRateProperty.set( this.maxDispensingRate ); // max rate seems to work fine
      }
    }
    this.previousPosition = this.positionProperty.get();
  }

Over in ShakerParticles, particle instances are created if:

if ( shaker.dispensingRateProperty.get() > 0 )

@samreid suggested creating a flag like this to suppress particle creation while the PhetioEngine is setting state. But we didn't get it to work in 15 minutes, so bailed.

const settingState = _.hasIn( window, 'phet.phetIo.phetioEngine' ) && phet.phetIo.phetioEngine.phetioStateEngine.isSettingState;

We'll return to this later.

pixelzoom commented 4 years ago

I created phetsims/phet-io#1624 to come up with a general solution to knowing when state is being restored. Assigned to the PhET-iO team. This issue is blocked until that is addressed.

pixelzoom commented 4 years ago

Over in phetsims/phet-io#1624, phet.joist.sim.isSettingPhetioStateProperty was added to determine whether PhetioEngine is setting state. I'll proceed with that.

pixelzoom commented 4 years ago

This was resolved by the above commits. Closing.

samreid commented 4 years ago

The second-to-previous commit left some code commented out that seemed suspicious. I discovered it as I was working on https://github.com/phetsims/tandem/issues/212.

Shaker has:

    options = merge( {
      // phetioType: ShakerIO
    }, options );

Is this meant to be commented out? If so, can ShakerIO be deleted?

pixelzoom commented 4 years ago

Is this meant to be commented out? If so, can ShakerIO be deleted?

I commented it out in 0d53c0d1b9b9f4a4c9f257aa6e7522b66e2a9442, but I suspect that was not intentional. I typically do not commit dead code.

I didn't instrument this sim, so I don't know why ShakerIO was instrumented, or if it needs to be. Probably a topic for #230.

samreid commented 3 years ago

On hold until #230 has progress.

pixelzoom commented 1 year ago

This problem no longer occurs. And shaker particles that were in motion continue to move from where they were when the Studio "Test" button was pressed. So nothing to do here, closing.