aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCalMWolfs <94038482+CalMWolfs@users.noreply.github.com>2024-04-19 20:04:55 +1000
committerGitHub <noreply@github.com>2024-04-19 12:04:55 +0200
commitef5e02d12b87e596aa7d808b2c912e91913466d3 (patch)
tree0ebacb99098bb8b9afb33f99cea27e07dfb6e8b6
parent00d43af42bcdd635fd95faaebe023a987cbb536d (diff)
downloadskyhanni-ef5e02d12b87e596aa7d808b2c912e91913466d3.tar.gz
skyhanni-ef5e02d12b87e596aa7d808b2c912e91913466d3.tar.bz2
skyhanni-ef5e02d12b87e596aa7d808b2c912e91913466d3.zip
Fix: Memory leak in ItemRenderBackground (#1491)
-rw-r--r--src/main/java/at/hannibal2/skyhanni/data/ItemRenderBackground.kt25
1 files changed, 10 insertions, 15 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/data/ItemRenderBackground.kt b/src/main/java/at/hannibal2/skyhanni/data/ItemRenderBackground.kt
index 406901b9d..ba150a72b 100644
--- a/src/main/java/at/hannibal2/skyhanni/data/ItemRenderBackground.kt
+++ b/src/main/java/at/hannibal2/skyhanni/data/ItemRenderBackground.kt
@@ -2,47 +2,42 @@ package at.hannibal2.skyhanni.data
import at.hannibal2.skyhanni.events.RenderRealOverlayEvent
import at.hannibal2.skyhanni.utils.LorenzUtils
+import at.hannibal2.skyhanni.utils.TimeLimitedCache
import net.minecraft.client.Minecraft
import net.minecraft.client.gui.Gui
import net.minecraft.client.renderer.GlStateManager
import net.minecraft.item.ItemStack
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
+import kotlin.time.Duration.Companion.milliseconds
class ItemRenderBackground {
companion object {
- private val backgroundColor = mutableMapOf<ItemStack, Int>()
- private val backgroundTime = mutableMapOf<ItemStack, Long>()
- private val borderLineColor = mutableMapOf<ItemStack, Int>()
- private val borderTime = mutableMapOf<ItemStack, Long>()
+ private val backgroundColour = TimeLimitedCache<ItemStack, Int>(60.milliseconds)
+ private val borderLineColour = TimeLimitedCache<ItemStack, Int>(60.milliseconds)
var ItemStack.background: Int
get() {
- if (System.currentTimeMillis() > backgroundTime.getOrDefault(this, 0) + 60) return -1
- return backgroundColor.getOrDefault(this, -1)
+ return backgroundColour.getOrNull(this) ?: -1
}
set(value) {
- backgroundColor[this] = value
- backgroundTime[this] = System.currentTimeMillis()
+ backgroundColour.put(this, value)
}
var ItemStack.borderLine: Int
get() {
- if (System.currentTimeMillis() > borderTime.getOrDefault(this, 0) + 60) return -1
- return borderLineColor.getOrDefault(this, -1)
+ return borderLineColour.getOrNull(this) ?: -1
}
set(value) {
- borderLineColor[this] = value
- borderTime[this] = System.currentTimeMillis()
+ borderLineColour.put(this, value)
}
}
@SubscribeEvent
- fun renderOverlayLol(event: RenderRealOverlayEvent) {
- val stack = event.stack
+ fun onRenderRealOverlay(event: RenderRealOverlayEvent) {
+ val stack = event.stack ?: return
if (!LorenzUtils.inSkyBlock) return
- if (stack == null) return
val backgroundColor = stack.background
if (backgroundColor != -1) {