Skip to content

Commit

Permalink
Merge pull request #7009 from samme/fix/7004-timer-event
Browse files Browse the repository at this point in the history
Prevent hanging timer events with repeat
  • Loading branch information
zekeatchan authored Jan 16, 2025
2 parents f5e0376 + 7d32c27 commit 748b7a6
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/time/Clock.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,11 @@ var Clock = new Class({
event.elapsed = event.startAt;
event.hasDispatched = false;
event.repeatCount = (event.repeat === -1 || event.loop) ? 999999999999 : event.repeat;

if (event.delay <= 0 && event.repeatCount > 0)
{
throw new Error('TimerEvent infinite loop created via zero delay');
}
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion src/time/TimerEvent.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ var TimerEvent = new Class({
this.hasDispatched = false;
this.repeatCount = (this.repeat === -1 || this.loop) ? 999999999999 : this.repeat;

if (this.delay === 0 && (this.repeat > 0 || this.loop))
if (this.delay <= 0 && this.repeatCount > 0)
{
throw new Error('TimerEvent infinite loop created via zero delay');
}
Expand Down

0 comments on commit 748b7a6

Please sign in to comment.