Skip to content

Conversation

@Dimon4eg
Copy link
Contributor

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
Copy link
Contributor Author

Dimon4eg commented May 9, 2017

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

@dumganhar
Copy link

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

@Dimon4eg
Copy link
Contributor Author

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

@minggo
Copy link

minggo commented Jan 23, 2018

@dumganhar any question about the issue?

@Dimon4eg
Copy link
Contributor Author

Dimon4eg commented Mar 13, 2018

@dumganhar any update?
The same fix already has been merged to C++ engine cocos2d/cocos2d-x#17706

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants