Closed zepumph closed 1 month ago
I was going to commit this, but ran into trouble when a multilink in the view updates because of the liquidVolumeProperty changes during model steps and updates in the view eagerly. This triggers a get() on the InterpolationProperty. This seems buggy to me, since we are mid, engine stepping, the interpolated value will be outdated. This intermediate state may be acceptable, but I couldn't be sure immediately.
@jonathanolson helped us understand the interpolation algorithm that interpolates between previousValue and currentValue (both of which are in the past relative to DT). Using these two values creates a notion of consistent speed, even if it is a bit "delayed". This depends on the notion that the whole view is looking at the interpolated values. So basically the view is one model step behind the view, but with consistency. This prevents jumpiness in exchange for a single step of delay.
Here is some paper trail about why we care about interpolation: https://github.com/phetsims/wave-on-a-string/issues/64
While testing on SR's computer. We found that model steps were running between 1-3 times per step. If there were 20 model steps between DTs, then interpolation is not that big of a deal. If the model fixed time step is greater than DT, then it is much more important to have interpolation to smooth out the timing.
Oscillation described in https://github.com/phetsims/buoyancy/issues/140#issuecomment-2118481755 is expected by p2 internals, says @jonathanolson.
Our conversation has made me want to try to continue to think about adding an assertion like this. I can be very buggy to access interpolated values from the model. Let's keep thinking about this.
Discussed this today with the Buoyancy Devs and we decided to leave this on hold until some other major changes to the model are in place. Afterwards, it's a matter of double checking if this is fine or not.
I refreshed the patch and committed to main behind a query parameter ?debugInterpolatedProperty
. Fuzzing with assertions enabled, it shows stacks that trigger an InterpolatedProperty read during the model step.
In my fuzzing, I saw updateScaleReadoutNode
, which is safe. The other one is:
// in Mass.ts
this.stepEmitter.addListener( () => this.contactForceBlendedProperty.step( this.contactForceInterpolatedProperty.value ) );
Which is blending incremental interpolates, which also seems reasonable to me.
@zepumph Want to do anything else here? You could fuzz with &debugInterpolatedProperty&fuzz
or we could revert the commit above, or review it.
I was able to get to a point where this could become an assertion. I don't know that we need this complexity, and noting here that it involved changing a multilink to a stepListener call so that we didn't call get from Multilink. I also turned it on by default so CT can report trouble. What do you think? Have I gone too far?
I discussed with @samreid, in addition to the above commit:
Let's see if CT complains before closing
CT showed 8 columns of solid green, nice work, closing.
From https://github.com/phetsims/buoyancy/issues/64, @samreid and I viewed that InterpolatedProperty instances were being read from inside the engine model step's postStepListener. This is generally a bug, and should instead use the
currentValue
. We think an assertion will help prevent future errors like this.Perhaps by wrapping the DBC model step with an
InterpolatedProperty.lock/unlock()
functionality.