From b29076d5ed67511165d41358d14727f2bdf1e614 Mon Sep 17 00:00:00 2001 From: Kam Date: Thu, 16 Nov 2023 15:08:25 -0500 Subject: [PATCH] Fix Memory Leak --- .../client/model/util/Model2DRenderer.java | 48 +++++++-------- .../client/model/util/ModelScaleRenderer.java | 60 +++++++++---------- 2 files changed, 54 insertions(+), 54 deletions(-) diff --git a/src/main/java/noppes/npcs/client/model/util/Model2DRenderer.java b/src/main/java/noppes/npcs/client/model/util/Model2DRenderer.java index 72c59888c..0cb4d163e 100644 --- a/src/main/java/noppes/npcs/client/model/util/Model2DRenderer.java +++ b/src/main/java/noppes/npcs/client/model/util/Model2DRenderer.java @@ -11,14 +11,14 @@ import org.lwjgl.opengl.GL11; public class Model2DRenderer extends ModelRenderer { - private boolean compiled; + private boolean compiledModel; + + private int displayListModel; - private int displayList; - private float x1, x2, y1, y2; private int width, height; private float rotationOffsetX, rotationOffsetY; - + private float scaleX = 1, scaleY = 1, thickness = 1; public Model2DRenderer(ModelBase par1ModelBase, float x, float y, int width, int height, float textureWidth, float textureHeight) { @@ -27,7 +27,7 @@ public class Model2DRenderer extends ModelRenderer { this.height = height; this.textureWidth = textureWidth; this.textureHeight = textureHeight; - + x1 = x / textureWidth; y1 = y / textureHeight; @@ -42,16 +42,16 @@ public class Model2DRenderer extends ModelRenderer { public void render(float par1) { if(!showModel || isHidden) return; - if(!compiled) - compileDisplayList(par1); - + if(!compiledModel) + compileDisplayListModel(par1); + GL11.glPushMatrix(); this.postRender(par1); - - GL11.glCallList(this.displayList); + + GL11.glCallList(this.displayListModel); GL11.glPopMatrix(); } - + public void setRotationOffset(float x, float y){ rotationOffsetX = x; rotationOffsetY = y; @@ -69,23 +69,23 @@ public class Model2DRenderer extends ModelRenderer { public void setThickness(float thickness) { this.thickness = thickness; } - @SideOnly(Side.CLIENT) - private void compileDisplayList(float par1) - { - this.displayList = GLAllocation.generateDisplayLists(1); - GL11.glNewList(this.displayList, GL11.GL_COMPILE); + @SideOnly(Side.CLIENT) + private void compileDisplayListModel(float par1) + { + this.displayListModel = GLAllocation.generateDisplayLists(1); + GL11.glNewList(this.displayListModel, GL11.GL_COMPILE); GL11.glScalef(scaleX * width / height, scaleY, thickness); - GL11.glRotatef(180, 1F, 0F, 0F); - if(mirror){ - GL11.glTranslatef(0, 0, -1f * par1); - GL11.glRotatef(180, 0, 1F, 0F); - } + GL11.glRotatef(180, 1F, 0F, 0F); + if(mirror){ + GL11.glTranslatef(0, 0, -1f * par1); + GL11.glRotatef(180, 0, 1F, 0F); + } GL11.glTranslated( rotationOffsetX * par1, rotationOffsetY * par1, 0); ItemRenderer.renderItemIn2D(Tessellator.instance, x1, y1, x2, y2, width, height, par1); - GL11.glEndList(); - this.compiled = true; - } + GL11.glEndList(); + this.compiledModel = true; + } } diff --git a/src/main/java/noppes/npcs/client/model/util/ModelScaleRenderer.java b/src/main/java/noppes/npcs/client/model/util/ModelScaleRenderer.java index 2e64ab9a5..586109151 100644 --- a/src/main/java/noppes/npcs/client/model/util/ModelScaleRenderer.java +++ b/src/main/java/noppes/npcs/client/model/util/ModelScaleRenderer.java @@ -10,51 +10,51 @@ import org.lwjgl.opengl.GL11; public class ModelScaleRenderer extends ModelRenderer { - public boolean compiled; + public boolean compiledModel; /** The GL display list rendered by the Tessellator for this model */ - public int displayList; - + public int displayListModel; + protected ModelScalePart config; - + public float x, y, z; - public ModelScaleRenderer(ModelBase par1ModelBase) { - super(par1ModelBase); - } + public ModelScaleRenderer(ModelBase par1ModelBase) { + super(par1ModelBase); + } public ModelScaleRenderer(ModelBase par1ModelBase, int par2, int par3) { this(par1ModelBase); this.setTextureOffset(par2, par3); } - + public void setConfig(ModelScalePart config, float x, float y, float z){ - this.config = config; - this.x = x; - this.y = y; - this.z = z; + this.config = config; + this.x = x; + this.y = y; + this.z = z; } - public void setRotation(ModelRenderer model, float x, float y, float z) { - model.rotateAngleX = x; - model.rotateAngleY = y; - model.rotateAngleZ = z; - } + public void setRotation(ModelRenderer model, float x, float y, float z) { + model.rotateAngleX = x; + model.rotateAngleY = y; + model.rotateAngleZ = z; + } public void render(float par1) { - if(!showModel || isHidden) - return; - if(!compiled) - compileDisplayList(par1); + if(!showModel || isHidden) + return; + if(!compiledModel) + compileDisplayListModel(par1); GL11.glPushMatrix(); GL11.glTranslatef(x, y, z); - if(config != null) - GL11.glTranslatef(0, 0, 0); + if(config != null) + GL11.glTranslatef(0, 0, 0); this.postRender(par1); - if(config != null) - GL11.glScalef(config.scaleX, config.scaleY, config.scaleZ); - GL11.glCallList(this.displayList); + if(config != null) + GL11.glScalef(config.scaleX, config.scaleY, config.scaleZ); + GL11.glCallList(this.displayListModel); if (this.childModels != null) { for (int i = 0; i < this.childModels.size(); ++i) @@ -65,10 +65,10 @@ public class ModelScaleRenderer extends ModelRenderer { GL11.glPopMatrix(); } - public void compileDisplayList(float par1) + public void compileDisplayListModel(float par1) { - this.displayList = GLAllocation.generateDisplayLists(1); - GL11.glNewList(this.displayList, GL11.GL_COMPILE); + this.displayListModel = GLAllocation.generateDisplayLists(1); + GL11.glNewList(this.displayListModel, GL11.GL_COMPILE); Tessellator tessellator = Tessellator.instance; for (int i = 0; i < this.cubeList.size(); ++i) @@ -77,7 +77,7 @@ public class ModelScaleRenderer extends ModelRenderer { } GL11.glEndList(); - this.compiled = true; + this.compiledModel = true; } }