Skip to content

Fix reschedule issue with same callback#3478

Open
Dimon4eg wants to merge 2 commits into
cocos2d:developfrom
Dimon4eg:fix-schedule-issue
Open

Fix reschedule issue with same callback#3478
Dimon4eg wants to merge 2 commits into
cocos2d:developfrom
Dimon4eg:fix-schedule-issue

Conversation

@Dimon4eg

Copy link
Copy Markdown
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

Dimon4eg commented May 9, 2017

Copy link
Copy Markdown
Contributor Author

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

@dumganhar

Copy link
Copy Markdown

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

@Dimon4eg

Copy link
Copy Markdown
Contributor Author

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

@minggo

minggo commented Jan 23, 2018

Copy link
Copy Markdown

@dumganhar any question about the issue?

@Dimon4eg

Dimon4eg commented Mar 13, 2018

Copy link
Copy Markdown
Contributor Author

@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