Closed pixelzoom closed 1 year ago
See ParticlesNode
and ParticlesCanvasNode
.
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.
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.
In the above commit, I documented the final solution. I also confirmed that count*Property
elements have correct values.
Closing.
For example: