From 5a0efce2c788ae47eaa3fe54a072a529af34ae78 Mon Sep 17 00:00:00 2001 From: LostLuma Date: Wed, 11 Sep 2024 13:24:15 +0200 Subject: [PATCH] Fix concurrent modification error modifying sound volume This is most likely caused by another mod inadvertently modifying the `instanceToChannel` map (by playing a sound?) from another thread. --- .../dynamic_fps/impl/mixin/SoundEngineMixin.java | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/platforms/common/src/main/java/dynamic_fps/impl/mixin/SoundEngineMixin.java b/platforms/common/src/main/java/dynamic_fps/impl/mixin/SoundEngineMixin.java index cb9cfe2b..154d914a 100644 --- a/platforms/common/src/main/java/dynamic_fps/impl/mixin/SoundEngineMixin.java +++ b/platforms/common/src/main/java/dynamic_fps/impl/mixin/SoundEngineMixin.java @@ -1,14 +1,12 @@ package dynamic_fps.impl.mixin; import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; import dynamic_fps.impl.feature.volume.SmoothVolumeHandler; import net.minecraft.client.Minecraft; import org.jetbrains.annotations.Nullable; -import org.spongepowered.asm.mixin.Final; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.Unique; +import org.spongepowered.asm.mixin.*; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @@ -39,6 +37,7 @@ public class SoundEngineMixin implements DuckSoundEngine { @Shadow @Final + @Mutable private Map instanceToChannel; @Shadow @@ -49,6 +48,13 @@ private float calculateVolume(SoundInstance instance) { @Unique private static final Minecraft dynamic_fps$minecraft = Minecraft.getInstance(); + @Inject(method = "", at = @At("TAIL")) + private void init(CallbackInfo callbackInfo) { + // Fix crash from another unknown mod mutating this + // While we're iterating over it in the `dynamic_fps$updateVolume` method + this.instanceToChannel = new ConcurrentHashMap<>(this.instanceToChannel); + } + @Override public void dynamic_fps$updateVolume(SoundSource source) { if (!this.loaded) {