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

prevent potential ThreadLocal memory leaks #2320

Merged
merged 1 commit into from
Jan 10, 2024
Merged
Show file tree
Hide file tree
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
15 changes: 12 additions & 3 deletions src/main/java/gregtech/api/block/machines/BlockMachine.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -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
Expand Down
9 changes: 7 additions & 2 deletions src/main/java/gregtech/api/pipenet/block/BlockPipe.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<PipeType, NodeDataType>) te);
super.harvestBlock(worldIn, player, pos, state, te, stack);
tileEntities.set(null);
tileEntities.remove();
}

@Override
Expand Down
14 changes: 11 additions & 3 deletions src/main/java/gregtech/api/unification/ore/OrePrefix.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/gregtech/asm/hooks/CTMHooks.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public static List<BakedQuad> getQuadsWithOptiFine(List<BakedQuad> 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;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Loading