Fix occasional crash due to unsafe concurrency with RenderTypes

This commit is contained in:
embeddedt 2023-01-01 19:34:29 -05:00
parent 9a4952aa42
commit e50859f10d
No known key found for this signature in database
GPG Key ID: A69433EC199B5613
3 changed files with 33 additions and 2 deletions

View File

@ -0,0 +1,28 @@
package org.embeddedt.modernfix.mixin;
import com.google.common.base.Preconditions;
import it.unimi.dsi.fastutil.objects.ObjectOpenCustomHashSet;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.client.renderer.vertex.VertexFormat;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Overwrite;
import org.spongepowered.asm.mixin.Shadow;
import java.util.Collections;
@Mixin(targets = {"net/minecraft/client/renderer/RenderType$Type"})
public class RenderTypeMixin {
@Shadow @Final private static ObjectOpenCustomHashSet<RenderType.Type> TYPES;
/**
* @author embeddedt
* @reason synchronize, can be accessed by multiple mods during modloading
*/
@Overwrite
private static RenderType.Type getOrCreate(String name, VertexFormat format, int drawMode, int bufferSize, boolean useDelegate, boolean needsSorting, RenderType.State renderState) {
synchronized (TYPES){
return TYPES.addOrGet(new RenderType.Type(name, format, drawMode, bufferSize, useDelegate, needsSorting, renderState));
}
}
}

View File

@ -1 +1,3 @@
public net.minecraft.client.Minecraft$WorldSelectionType
public net.minecraft.client.Minecraft$WorldSelectionType
public net.minecraft.client.renderer.RenderType$Type
public net.minecraft.client.renderer.RenderType$Type <init>(Ljava/lang/String;Lnet/minecraft/client/renderer/vertex/VertexFormat;IIZZLnet/minecraft/client/renderer/RenderType$State;)V

View File

@ -11,7 +11,8 @@
"SaveFormatAccessor"
],
"client": [
"MinecraftMixin"
"MinecraftMixin",
"RenderTypeMixin"
],
"injectors": {
"defaultRequire": 1