Skip to content

Commit

Permalink
Fix concurrent modification error modifying sound volume
Browse files Browse the repository at this point in the history
This is most likely caused by another mod inadvertently modifying
the `instanceToChannel` map (by playing a sound?) from another thread.
  • Loading branch information
LostLuma committed Sep 11, 2024
1 parent 87de158 commit 5a0efce
Showing 1 changed file with 10 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -39,6 +37,7 @@ public class SoundEngineMixin implements DuckSoundEngine {

@Shadow
@Final
@Mutable
private Map<SoundInstance, ChannelAccess.ChannelHandle> instanceToChannel;

@Shadow
Expand All @@ -49,6 +48,13 @@ private float calculateVolume(SoundInstance instance) {
@Unique
private static final Minecraft dynamic_fps$minecraft = Minecraft.getInstance();

@Inject(method = "<init>", 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) {
Expand Down

0 comments on commit 5a0efce

Please sign in to comment.