Skip to content

Commit

Permalink
Copy tasks since running a task can modify postedTasks.
Browse files Browse the repository at this point in the history
  • Loading branch information
NathanSweet committed Apr 29, 2024
1 parent e31c43a commit fbf4107
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions gdx/src/com/badlogic/gdx/utils/Timer.java
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ static class TimerThread implements Runnable, LifecycleListener {
long pauseTimeMillis;

final Array<Task> postedTasks = new Array(2);
final Array<Task> runTasks = new Array(2);
private final Runnable runPostedTasks = new Runnable() {
public void run () {
runPostedTasks();
Expand Down Expand Up @@ -313,11 +314,13 @@ public void run () {

void runPostedTasks () {
synchronized (postedTasks) {
Object[] items = postedTasks.items;
for (int i = 0, n = postedTasks.size; i < n; i++)
((Task)items[i]).run();
runTasks.addAll(postedTasks);
postedTasks.clear();
}
Object[] items = runTasks.items;
for (int i = 0, n = runTasks.size; i < n; i++)
((Task)items[i]).run();
runTasks.clear();
}

void addPostedTask (Task task) {
Expand Down

0 comments on commit fbf4107

Please sign in to comment.