From 7331811bd1ffb5911868022d42e536ac76eada3b Mon Sep 17 00:00:00 2001 From: Kli Kli Date: Tue, 8 Oct 2024 07:25:40 +0200 Subject: [PATCH] fix: memory leak Closes #1227 --- .../emi/render/SpiritRenderable.java | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/klikli_dev/occultism/integration/emi/render/SpiritRenderable.java b/src/main/java/com/klikli_dev/occultism/integration/emi/render/SpiritRenderable.java index 98ea347b4..1e0d89807 100644 --- a/src/main/java/com/klikli_dev/occultism/integration/emi/render/SpiritRenderable.java +++ b/src/main/java/com/klikli_dev/occultism/integration/emi/render/SpiritRenderable.java @@ -1,27 +1,29 @@ package com.klikli_dev.occultism.integration.emi.render; import com.klikli_dev.occultism.client.gui.spirit.SpiritGui; -import com.klikli_dev.occultism.common.entity.spirit.FoliotEntity; import com.klikli_dev.occultism.common.entity.spirit.SpiritEntity; -import com.klikli_dev.occultism.registry.OccultismEntities; import dev.emi.emi.api.render.EmiRenderable; -import dev.emi.emi.api.widget.DrawableWidget; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiGraphics; import net.minecraft.world.entity.EntityType; +import java.lang.ref.WeakReference; -public class SpiritRenderable implements EmiRenderable{ - T spiritEntity; + +public class SpiritRenderable implements EmiRenderable { + WeakReference spiritEntity; EntityType spiritType; + public SpiritRenderable(EntityType spiritType) { - this.spiritType=spiritType; + this.spiritType = spiritType; } @Override public void render(GuiGraphics draw, int x, int y, float delta) { - if(spiritEntity==null) - spiritEntity= (T) spiritType.create(Minecraft.getInstance().level); - SpiritGui.drawEntityToGui(draw, (int) (x+8),(int)(y+(spiritEntity.getEyeHeight()*15)+5),15,1,1,spiritEntity); + if (this.spiritEntity == null || this.spiritEntity.get() == null) + this.spiritEntity = new WeakReference<>(this.spiritType.create(Minecraft.getInstance().level)); + + + SpiritGui.drawEntityToGui(draw, x + 8, (int) (y + (this.spiritEntity.get().getEyeHeight() * 15) + 5), 15, 1, 1, this.spiritEntity.get()); } }