phetsims / acid-base-solutions

"Acid-Base Solutions" is an educational simulation in HTML5, by PhET Interactive Simulations.
http://phet.colorado.edu/sims/html/acid-base-solutions/latest/acid-base-solutions_en.html
GNU General Public License v3.0
4 stars 7 forks source link

Particles view is not correct in State wrapper #195

Closed pixelzoom closed 1 year ago

pixelzoom commented 1 year ago

For example:

screenshot_2684
pixelzoom commented 1 year ago

See ParticlesNode and ParticlesCanvasNode.

pixelzoom commented 1 year ago

ParticlesCanvasNode has a data structure that looks like this:

// Data structure used to store information for each unique type of particle
type ParticlesData = {
  canvas: HTMLCanvasElement | null;

  // This is a Property so that it can be inspected in Studio and the PhET-iO data stream.
  countProperty: Property<number>;

  // Note that particle positions are not PhET-iO stateful. See https://github.com/phetsims/acid-base-solutions/issues/201
  xCoordinates: Float32Array;
  yCoordinates: Float32Array;
};

If I replace countProperty: Property<number> with count: number and adjust the code accordingly, the problem goes away -- the Particles view is properly restored in the State wrapper.

So when the countProperty elements are being restored, that's somehow messing things up. But I don't understand why yet.

pixelzoom commented 1 year ago

Until I understand this, the workaround in the above commit includes both countProperty: Property<number> and count: number. And count is used to determine how many particles to add/remove in paintCanvas

Something else to check is whether the count*Property elements have correct values in the State wrapper's downstream sim.

pixelzoom commented 1 year ago

In the above commit, I documented the final solution. I also confirmed that count*Property elements have correct values.

Closing.