From 5ee5bc4303e3ba9239e42f6a5231cea684c7fa8a Mon Sep 17 00:00:00 2001 From: TechLord22 <37029404+techlord22@users.noreply.github.com> Date: Tue, 26 Dec 2023 13:18:03 -0500 Subject: [PATCH] prevent potential ThreadLocal memory leaks --- .../gregtech/api/block/machines/BlockMachine.java | 15 ++++++++++++--- .../gregtech/api/pipenet/block/BlockPipe.java | 9 +++++++-- .../gregtech/api/unification/ore/OrePrefix.java | 14 +++++++++++--- src/main/java/gregtech/asm/hooks/CTMHooks.java | 2 +- .../renderer/handler/MetaTileEntityRenderer.java | 2 +- .../client/renderer/pipe/PipeRenderer.java | 2 +- 6 files changed, 33 insertions(+), 11 deletions(-) diff --git a/src/main/java/gregtech/api/block/machines/BlockMachine.java b/src/main/java/gregtech/api/block/machines/BlockMachine.java index f9a77ccbe07..d2deda21283 100644 --- a/src/main/java/gregtech/api/block/machines/BlockMachine.java +++ b/src/main/java/gregtech/api/block/machines/BlockMachine.java @@ -40,7 +40,11 @@ import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.*; +import net.minecraft.util.BlockRenderLayer; +import net.minecraft.util.EnumBlockRenderType; +import net.minecraft.util.EnumFacing; +import net.minecraft.util.EnumHand; +import net.minecraft.util.NonNullList; import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.RayTraceResult; @@ -63,7 +67,12 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.util.*; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.Random; +import java.util.Set; import static gregtech.api.util.GTUtility.getMetaTileEntity; @@ -423,7 +432,7 @@ public void harvestBlock(@NotNull World worldIn, @NotNull EntityPlayer player, @ @NotNull IBlockState state, @Nullable TileEntity te, @NotNull ItemStack stack) { tileEntities.set(te == null ? tileEntities.get() : ((IGregTechTileEntity) te).getMetaTileEntity()); super.harvestBlock(worldIn, player, pos, state, te, stack); - tileEntities.set(null); + tileEntities.remove(); } @Nullable diff --git a/src/main/java/gregtech/api/pipenet/block/BlockPipe.java b/src/main/java/gregtech/api/pipenet/block/BlockPipe.java index 5468aae38dd..667b67fcf52 100644 --- a/src/main/java/gregtech/api/pipenet/block/BlockPipe.java +++ b/src/main/java/gregtech/api/pipenet/block/BlockPipe.java @@ -34,7 +34,12 @@ import net.minecraft.item.EnumDyeColor; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.*; +import net.minecraft.util.BlockRenderLayer; +import net.minecraft.util.EnumActionResult; +import net.minecraft.util.EnumFacing; +import net.minecraft.util.EnumHand; +import net.minecraft.util.NonNullList; +import net.minecraft.util.SoundCategory; import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.RayTraceResult; @@ -485,7 +490,7 @@ public void harvestBlock(@NotNull World worldIn, @NotNull EntityPlayer player, @ @NotNull IBlockState state, @Nullable TileEntity te, @NotNull ItemStack stack) { tileEntities.set(te == null ? tileEntities.get() : (IPipeTile) te); super.harvestBlock(worldIn, player, pos, state, te, stack); - tileEntities.set(null); + tileEntities.remove(); } @Override diff --git a/src/main/java/gregtech/api/unification/ore/OrePrefix.java b/src/main/java/gregtech/api/unification/ore/OrePrefix.java index 30239988324..0a159028f1d 100644 --- a/src/main/java/gregtech/api/unification/ore/OrePrefix.java +++ b/src/main/java/gregtech/api/unification/ore/OrePrefix.java @@ -23,7 +23,15 @@ import stanhebben.zenscript.annotations.ZenClass; import stanhebben.zenscript.annotations.ZenMethod; -import java.util.*; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; import java.util.concurrent.atomic.AtomicInteger; import java.util.function.Function; import java.util.function.Predicate; @@ -631,11 +639,11 @@ private void runGeneratedMaterialHandlers() { for (IOreRegistrationHandler registrationHandler : oreProcessingHandlers) { registrationHandler.processMaterial(this, registeredMaterial); } - currentMaterial.set(null); + currentMaterial.remove(); } // clear generated materials for next pass generatedMaterials.clear(); - currentProcessingPrefix.set(null); + currentProcessingPrefix.remove(); } public void setAlternativeOreName(String name) { diff --git a/src/main/java/gregtech/asm/hooks/CTMHooks.java b/src/main/java/gregtech/asm/hooks/CTMHooks.java index 33ddc0d7754..eaf4f7ad51c 100644 --- a/src/main/java/gregtech/asm/hooks/CTMHooks.java +++ b/src/main/java/gregtech/asm/hooks/CTMHooks.java @@ -43,7 +43,7 @@ public static List getQuadsWithOptiFine(List ret, BlockRen ForgeHooksClient.setRenderLayer(BloomEffectUtil.getBloomLayer()); result.addAll(bakedModel.getQuads(state, side, rand)); ForgeHooksClient.setRenderLayer(layer); - CTMHooks.ENABLE.set(null); + CTMHooks.ENABLE.remove(); return result; } } diff --git a/src/main/java/gregtech/client/renderer/handler/MetaTileEntityRenderer.java b/src/main/java/gregtech/client/renderer/handler/MetaTileEntityRenderer.java index 5aa513fea8c..9436d30dc8d 100644 --- a/src/main/java/gregtech/client/renderer/handler/MetaTileEntityRenderer.java +++ b/src/main/java/gregtech/client/renderer/handler/MetaTileEntityRenderer.java @@ -115,7 +115,7 @@ public boolean renderBlock(IBlockAccess world, BlockPos pos, IBlockState state, metaTileEntity.renderCovers(renderState, translation.copy(), renderLayer); - Textures.RENDER_STATE.set(null); + Textures.RENDER_STATE.remove(); return true; } diff --git a/src/main/java/gregtech/client/renderer/pipe/PipeRenderer.java b/src/main/java/gregtech/client/renderer/pipe/PipeRenderer.java index 632bdad8f2b..d16ca9ace07 100644 --- a/src/main/java/gregtech/client/renderer/pipe/PipeRenderer.java +++ b/src/main/java/gregtech/client/renderer/pipe/PipeRenderer.java @@ -218,7 +218,7 @@ public boolean renderBlock(IBlockAccess world, BlockPos pos, IBlockState state, CoverHolder coverHolder = pipeTile.getCoverableImplementation(); coverHolder.renderCovers(renderState, new Matrix4().translate(pos.getX(), pos.getY(), pos.getZ()), renderLayer); - Textures.RENDER_STATE.set(null); + Textures.RENDER_STATE.remove(); } return true; }