From 3f3700af4f32f9d744356a86cca69c2596491c08 Mon Sep 17 00:00:00 2001 From: "Luis C.M" <42545778+c0508383@users.noreply.github.com> Date: Sun, 24 Mar 2024 03:26:23 -0500 Subject: [PATCH] fixed concurrent exception thrown when removing animations from being ticked --- src/main/java/noppes/npcs/CommonProxy.java | 12 ++++++++---- .../noppes/npcs/controllers/data/AnimationData.java | 6 ++++-- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/main/java/noppes/npcs/CommonProxy.java b/src/main/java/noppes/npcs/CommonProxy.java index 08510d08e..bc49db973 100644 --- a/src/main/java/noppes/npcs/CommonProxy.java +++ b/src/main/java/noppes/npcs/CommonProxy.java @@ -23,11 +23,12 @@ import noppes.npcs.controllers.data.PlayerData; import noppes.npcs.entity.EntityNPCInterface; import noppes.npcs.util.MillisTimer; +import java.util.ConcurrentModificationException; import java.util.HashSet; public class CommonProxy implements IGuiHandler { - public static HashSet clientPlayingAnimations = new HashSet<>(); - public static HashSet serverPlayingAnimations = new HashSet<>(); + public final static HashSet clientPlayingAnimations = new HashSet<>(); + public final static HashSet serverPlayingAnimations = new HashSet<>(); protected MillisTimer animationTimer = new MillisTimer(1000); protected long totalTicks; @@ -55,8 +56,11 @@ public class CommonProxy implements IGuiHandler { totalTicks++; } totalTicks %= 60 * 60 * 1000; - clientPlayingAnimations.removeIf(CommonProxy.this::removeAnimation); - serverPlayingAnimations.removeIf(CommonProxy.this::removeAnimation); + + try { + clientPlayingAnimations.removeIf(CommonProxy.this::removeAnimation); + serverPlayingAnimations.removeIf(CommonProxy.this::removeAnimation); + } catch (ConcurrentModificationException ignored) {} } }}); thread.setDaemon(true); diff --git a/src/main/java/noppes/npcs/controllers/data/AnimationData.java b/src/main/java/noppes/npcs/controllers/data/AnimationData.java index 3bfb538c5..d89a56ae4 100644 --- a/src/main/java/noppes/npcs/controllers/data/AnimationData.java +++ b/src/main/java/noppes/npcs/controllers/data/AnimationData.java @@ -167,8 +167,10 @@ public class AnimationData implements IAnimationData { } if (CustomNpcs.proxy.hasClient() && newAnim != null) { - CommonProxy.clientPlayingAnimations.remove(this.animation); - CommonProxy.clientPlayingAnimations.add(newAnim); + synchronized (CommonProxy.clientPlayingAnimations) { + CommonProxy.clientPlayingAnimations.remove(this.animation); + CommonProxy.clientPlayingAnimations.add(newAnim); + } } this.animation = newAnim;