cocos2d-html5
cocos2d-html5 copied to clipboard
Fix reschedule issue with same callback
The issue:
- create timer with some repeat count cc.director.getScheduler().schedule(callback, target, interval, repeat, delay, paused, key);
- wait for last repeat executed
- in timer callback reschedule it again with the same callback
- as result timer is broken and will never be executed
Reason:
When we reschedule timer again from callback the scheduler just updates interval value:
timer._interval = interval;
After callback executed timer will be canceled:
if (this._callback && !this._runForever && this._timesExecuted > this._repeat)
this.cancel();
Fix: Scheduler will update interval only for not exhausted timers (still running). In our case, it will create new internal timer object and old one will be canceled after callback.
Please don't merge yet. I'll sync it with PR for cocos2d-x
@Dimon4eg , could this PR be ready for merge now?
Done. Also added test for this issue in cocos2d-x repo.
@dumganhar any question about the issue?
@dumganhar any update? The same fix already has been merged to C++ engine https://github.com/cocos2d/cocos2d-x/pull/17706