mirror of
https://github.com/GTNewHorizons/Chisel.git
synced 2026-11-23 21:59:51 +00:00
Fix world client memory leaks caused by block renderers (#88)
* make threadlocals final * minor code fixes * fix custom block renderers leaking world * remove now useless threadlocal cleaning * fix memory leak from rendererOld by just deleting the field * fix ThreadLocals to work on dedicated server
This commit is contained in:
1 parent
2ae1f8ba93
commit
ec610dc876
17 files changed
+114
-203
No files matched your search
@@ -14,10 +14,10 @@ import team.chisel.ctmlib.ISubmapManager;
|
||||
|
||||
public class VariationInfoBase implements IVariationInfo {
|
||||
|
||||
private ICarvingVariation variation;
|
||||
private String unlocDesc;
|
||||
private ISubmapManager manager;
|
||||
private TextureType type;
|
||||
private final ICarvingVariation variation;
|
||||
private final String unlocDesc;
|
||||
private final ISubmapManager manager;
|
||||
private final TextureType type;
|
||||
|
||||
public VariationInfoBase(ICarvingVariation variation, String unlocDesc, ISubmapManager manager) {
|
||||
this(variation, unlocDesc, manager, TextureType.CUSTOM);
|
||||
|
||||
@@ -19,6 +19,7 @@ import org.apache.commons.lang3.tuple.Triple;
|
||||
import com.cricketcraft.chisel.api.carving.CarvableHelper;
|
||||
import com.cricketcraft.chisel.api.carving.ICarvingVariation;
|
||||
|
||||
import cpw.mods.fml.relauncher.FMLLaunchHandler;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import team.chisel.ctmlib.CTM;
|
||||
@@ -91,9 +92,9 @@ public enum TextureType {
|
||||
TextureSubmap map = data.getLeft();
|
||||
if (topConnected && botConnected)
|
||||
return map.getSubIcon(0, 1);
|
||||
if (topConnected && !botConnected)
|
||||
if (topConnected)
|
||||
return map.getSubIcon(1, 1);
|
||||
if (!topConnected && botConnected)
|
||||
if (botConnected)
|
||||
return map.getSubIcon(1, 0);
|
||||
return map.getSubIcon(0, 0);
|
||||
}
|
||||
@@ -101,11 +102,9 @@ public enum TextureType {
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
protected RenderBlocks createRenderContext(RenderBlocks rendererOld, IBlockAccess world, Object cachedObject) {
|
||||
TextureType.initStatics();
|
||||
RenderBlocksColumn ret = theRenderBlocksColumn.get();
|
||||
Pair<TextureSubmap, IIcon> data = (Pair<TextureSubmap, IIcon>) cachedObject;
|
||||
|
||||
ret.blockAccess = world;
|
||||
ret.renderMaxX = 1.0;
|
||||
ret.renderMaxY = 1.0;
|
||||
ret.renderMaxZ = 1.0;
|
||||
@@ -207,15 +206,12 @@ public enum TextureType {
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
protected RenderBlocks createRenderContext(RenderBlocks rendererOld, IBlockAccess world, Object cachedObject) {
|
||||
TextureType.initStatics();
|
||||
RenderBlocksCTM ret = theRenderBlocksCTM.get();
|
||||
Triple<?, TextureSubmap, TextureSubmap> data = (Triple<?, TextureSubmap, TextureSubmap>) cachedObject;
|
||||
ret.blockAccess = world;
|
||||
|
||||
ret.submap = data.getMiddle();
|
||||
ret.submapSmall = data.getRight();
|
||||
|
||||
ret.rendererOld = rendererOld;
|
||||
return ret;
|
||||
}
|
||||
},
|
||||
@@ -332,33 +328,18 @@ public enum TextureType {
|
||||
private static final TextureType[] VALUES;
|
||||
private static final CTM ctm = CTM.getInstance();
|
||||
private static final Random rand = new Random();
|
||||
@SideOnly(Side.CLIENT)
|
||||
private static ThreadLocal<RenderBlocksCTM> theRenderBlocksCTM;
|
||||
@SideOnly(Side.CLIENT)
|
||||
private static ThreadLocal<RenderBlocksColumn> theRenderBlocksColumn;
|
||||
private static final ThreadLocal<RenderBlocksCTM> theRenderBlocksCTM = FMLLaunchHandler.side().isClient() ? ThreadLocal.withInitial(RenderBlocksCTM::new) : null;
|
||||
private static final ThreadLocal<RenderBlocksColumn> theRenderBlocksColumn = FMLLaunchHandler.side().isClient() ? ThreadLocal.withInitial(RenderBlocksColumn::new) : null;
|
||||
|
||||
private String[] suffixes;
|
||||
private final String[] suffixes;
|
||||
static {
|
||||
VALUES = ArrayUtils.subarray(values(), 0, values().length - 1);
|
||||
}
|
||||
|
||||
private TextureType(String... suffixes) {
|
||||
TextureType(String... suffixes) {
|
||||
this.suffixes = suffixes.length == 0 ? new String[] { "" } : suffixes;
|
||||
}
|
||||
|
||||
private static void initStatics() {
|
||||
if (theRenderBlocksCTM == null) {
|
||||
theRenderBlocksCTM = ThreadLocal.withInitial(RenderBlocksCTM::new);
|
||||
theRenderBlocksColumn = ThreadLocal.withInitial(RenderBlocksColumn::new);
|
||||
}
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public static void clearStatics() {
|
||||
if(theRenderBlocksCTM != null) theRenderBlocksCTM.remove();
|
||||
if(theRenderBlocksColumn != null) theRenderBlocksColumn.remove();
|
||||
}
|
||||
|
||||
public ISubmapManager createManagerFor(ICarvingVariation variation, String texturePath) {
|
||||
return new SubmapManagerDefault(this, variation, texturePath);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user