From 2846ff7172d308102c6a1f57d2c147237e80d635 Mon Sep 17 00:00:00 2001 From: vddcore <573729-vddcore@users.noreply.gitlab.com> Date: Sun, 3 Jul 2022 07:20:24 +0000 Subject: [PATCH] Fixed seemingly random server crashes caused by ArrayIndexOutOfBoundsException on unsafe type during threaded operations by synchronizing add/remove logic for PulseRunner.TASKS --- Server/src/main/kotlin/rs09/game/world/PulseRunner.kt | 5 ++++- Server/src/main/kotlin/rs09/worker/MajorUpdateWorker.kt | 4 +++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/Server/src/main/kotlin/rs09/game/world/PulseRunner.kt b/Server/src/main/kotlin/rs09/game/world/PulseRunner.kt index 143986e89..67c00794f 100644 --- a/Server/src/main/kotlin/rs09/game/world/PulseRunner.kt +++ b/Server/src/main/kotlin/rs09/game/world/PulseRunner.kt @@ -10,8 +10,11 @@ import java.util.* class PulseRunner { val TASKS = ArrayList() + fun submit(pulse: Pulse){ - TASKS.add(pulse) + synchronized(this.TASKS) { + TASKS.add(pulse) + } } } /* diff --git a/Server/src/main/kotlin/rs09/worker/MajorUpdateWorker.kt b/Server/src/main/kotlin/rs09/worker/MajorUpdateWorker.kt index 438c9223d..6a3728878 100644 --- a/Server/src/main/kotlin/rs09/worker/MajorUpdateWorker.kt +++ b/Server/src/main/kotlin/rs09/worker/MajorUpdateWorker.kt @@ -106,7 +106,9 @@ class MajorUpdateWorker { //remove all null or finished pulses from the list rmlist.forEach { - GameWorld.Pulser.TASKS.remove(it) + synchronized(GameWorld.Pulser.TASKS) { + GameWorld.Pulser.TASKS.remove(it) + } } rmlist.clear()