Skip to content

Commit

Permalink
Merge pull request #221 from LostLuma/fix/concurrent-sound-engine-crash
Browse files Browse the repository at this point in the history
Fix concurrent modification error modifying sound volume
  • Loading branch information
LostLuma authored Sep 11, 2024
2 parents 634a020 + 5a0efce commit c02688a
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 c02688a

Please sign in to comment.