Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix concurrent modification error modifying sound volume #221

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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