cocos2d-html5 icon indicating copy to clipboard operation
cocos2d-html5 copied to clipboard

Fix reschedule issue with same callback

Open Dimon4eg opened this issue 7 years ago • 5 comments

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.

Dimon4eg avatar Apr 14 '17 20:04 Dimon4eg

Please don't merge yet. I'll sync it with PR for cocos2d-x

Dimon4eg avatar May 09 '17 11:05 Dimon4eg

@Dimon4eg , could this PR be ready for merge now?

dumganhar avatar Jan 19 '18 10:01 dumganhar

Done. Also added test for this issue in cocos2d-x repo.

Dimon4eg avatar Jan 21 '18 12:01 Dimon4eg

@dumganhar any question about the issue?

minggo avatar Jan 23 '18 01:01 minggo

@dumganhar any update? The same fix already has been merged to C++ engine https://github.com/cocos2d/cocos2d-x/pull/17706

Dimon4eg avatar Mar 13 '18 11:03 Dimon4eg