1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2025-06-06 08:34:12 +00:00

Fix ConcurrentModificationException caused by timers

This commit is contained in:
Fox2Code 2025-04-29 21:14:14 +02:00
parent 22c094192b
commit 00e57227dc
No known key found for this signature in database
GPG Key ID: 39238D7B921A8C76

View File

@ -203,9 +203,11 @@ public class OSAPI implements ILuaAPI {
*/ */
@LuaFunction @LuaFunction
public final int startTimer(double timer) throws LuaException { public final int startTimer(double timer) throws LuaException {
synchronized (timers) {
timers.put(nextTimerToken, new Timer((int) Math.round(checkFinite(0, timer) / 0.05))); timers.put(nextTimerToken, new Timer((int) Math.round(checkFinite(0, timer) / 0.05)));
return nextTimerToken++; return nextTimerToken++;
} }
}
/** /**
* Cancels a timer previously started with startTimer. This will stop the * Cancels a timer previously started with startTimer. This will stop the
@ -217,8 +219,10 @@ public class OSAPI implements ILuaAPI {
*/ */
@LuaFunction @LuaFunction
public final void cancelTimer(int token) { public final void cancelTimer(int token) {
synchronized (timers) {
timers.remove(token); timers.remove(token);
} }
}
/** /**
* Sets an alarm that will fire at the specified in-game time. When it * Sets an alarm that will fire at the specified in-game time. When it