cubiq / iscroll

Smooth scrolling for the web
http://iscrolljs.com
MIT License
12.87k stars 3.8k forks source link

freeze after division by zero #1161

Open sp-kilobug opened 7 years ago

sp-kilobug commented 7 years ago

There is a "not so uncommon" bug case causing iscroll v5.2.0-snapshot to freeze. According to _move(), after 300ms, this.startTime is reseted to current timestamp https://github.com/cubiq/iscroll/blob/master/build/iscroll.js#L606 If you release the pointer at this moment, the _end function is called with a
duration = utils.getTime() - this.startTime = 0 As a side effect, if this.y == this.startY when releasing the mouse button, we have a 0/0 = NaN in utils.momentum https://github.com/cubiq/iscroll/blob/master/build/iscroll.js#L58 causing newY = momentumY.destination = NaN https://github.com/cubiq/iscroll/blob/master/build/iscroll.js#L671 After that, properties are corrupted with NaN values causing iscroll to freeze.

I'm currently testing this fix at l.607 : this.startTime = timestamp - 1;