Closed pixelzoom closed 9 months ago
Reproduced in the HTML5 version:
When this occurs, the "Flip Polarity" button also looks like it's stuck in the "down" position for a moment after pressing it.
I verified that coil.currentAmplitudeProperty
and lightBulb.brightnessProperty
are indeed changing as expected. But that occassionally results in no change to the view -- i.e., no visible rays.
In the Unfuddle ticket (see above), Mike Dubson said:
I believe the best long-term solution is to alter the model (slightly) to include damping, as is done in the flash sim Faraday's law, so that single-time-step changes are smoothed out over several time-steps.
It's not clear whether that damping was ported to the HTML5 version of faradays-law. But poking around, I suspect that it is the step
method in Voltmeter.js, because BulbNode.js uses voltmeter.voltageProperty.
Since there's already (broken? see #73) damping in FEL's Voltmeter.ts, I might be better off using that, than trying to extract something from faradays-law. And we may need to turn damping off when using the AC power supply.
Looking for a quick-&-dirty workaround, I tried changing the bulb's brightness in the next animaton frame, but that did not resolve the problem.
Here's the diff for LightBulb.ts. I tried this with both stepTimer and animatonFrameTimer.
- this._brightnessProperty.value = brightness;
+ stepTimer.runOnNextTick( () => {
+ this._brightnessProperty.value = brightness;
+ } );
Discussed with @jonathanolson on Zoom.
The problem is likely with the use of ConstantDtClock. It looks like LightBulb is occassionally getting stepped multiple times per animation frame, so currentAmplitude goes from 0 => peak => 0, and we therefore don't see the peak.
@jonathanolson pointed me to phet-core's EventTimer
, and we discussed various strategies for interpolating what happens between animation frames.
In https://github.com/phetsims/faradays-electromagnetic-lab/commit/812e73ca614ce47c5c5639d1db09745419d14f07, I reimplemented ConstantDtClock as a subclass of EventTimer. So that I didn't need to change the API of ConstantDtClock, I added the ability to add listeners.
The problem with the light bulb is still present, because I haven't changed anything to address when the case where calling EventTimer step
results in multiple calls to its eventCallback
.
This problem seems to have gone away after reimplementing the electrons view using scenery Sprites, see https://github.com/phetsims/faradays-electromagnetic-lab/issues/49#issuecomment-1965394557. The "Flip Polarity" button no longer stays stuck down, and I don't see any missing light rays. My hypothesis is that there was an occassional GC happening, possibly due to the addChild/removeChild approach of the previous implementation of electrons (which was also used in the Java version, where this bug was first reported), and we were occassionally hitting that GC.
I'll leave this open, and bang on it a bit more to be sure.
I pressed the "Flip Polarity" button 300 times and never encountered this problem. I used to consistently hit the problem in 15-20 presses. So I think it's safe to consider this resolved and close this issue.
Reopening because there is a TODO marked for this issue.
This problem is still occurring, was reported for https://github.com/phetsims/qa/issues/1091, and is now being tracked in https://github.com/phetsims/faradays-electromagnetic-lab/issues/180.
For #8... Reported by Mike Dubson in https://phet.unfuddle.com/a#/projects/9404/tickets/by_number/3552 on 6/14/2013:
Rather than make significant changes to the model to incorporate damping (as described above), it might be preferrable to add a workaround for this specific case. We'll see...