phetsims / unit-rates

"Unit Rates" is an educational simulation in HTML5, by PhET Interactive Simulations.
GNU General Public License v3.0
0 stars 2 forks source link

Assertion failed: invalid t: NaN #215

Closed pixelzoom closed 4 years ago

pixelzoom commented 4 years ago

Steps to reproduce:

  1. Start sim with ?ea
  2. Go to Shopping screen
  3. Open denominator keypad, enter "333"
  4. Open denominator keypad, enter "334"
VM551 assert.js:22 Uncaught Error: Assertion failed: invalid t: NaN
    at window.assertions.assertFunction (VM551 assert.js:22)
    at Easing.polynomialEaseInOutValue (Easing.js?bust=1578505280788:112)
    at AnimationTarget.update (AnimationTarget.js?bust=1578505280788:217)
    at Animation.step (Animation.js?bust=1578505280788:314)
    at Animation.start (Animation.js?bust=1578505280788:240)
    at markerEditorObserver (DoubleNumberLineAccordionBox.js?bust=1578505280788:276)
    at TinyEmitter.emit (TinyEmitter.js?bust=1578505280788:68)
    at Property._notifyListeners (Property.js?bust=1578505280788:275)
    at Property.set (Property.js?bust=1578505280788:176)
    at Property.set value [as value] (Property.js?bust=1578505280788:345)
pixelzoom commented 4 years ago

I thought this might be related to changes made for phetsims/phet-info#126, but I rolled back to 84fbf5bc6f4fb1783bb99649ca365cb0d51401e9 and that's not the case.

I'm guessing this is failing because the distance to animate is zero. So that probably results in a divide-by-zero error somewhere.

pixelzoom commented 4 years ago

Here's the divide-by-zero problem, in Animation.js:

312 const ratio = Utils.clamp( ( this.length - this.remainingAnimation ) / this.length, 0, 1 );

this.length is the computed duration of the animation (in seconds), and it's 0 because the start and end positions are the same.

pixelzoom commented 4 years ago

This is a general problem with Animation, which I've reported in https://github.com/phetsims/twixt/issues/27. If the marker doesn't need to move, then the Animation has duration: 0, and that will fail with a divide-by-zero (NaN) error.

This problem was introduced in this sim when MoveTo was replaced by Animation on 8/24/18. I'm going to work around it by adding logic to create the Animation only when duration > 0.

pixelzoom commented 4 years ago

Fixed in the above commit. Since this issue never appeared in a released version, I'm going to go ahead and close it.

pixelzoom commented 4 years ago

Since phetsims/twixt#27 has been fixed, I removed the workaround that was added in https://github.com/phetsims/unit-rates/commit/b66d080e503e261c0b4ea610cae7c61a5a6bec5c.