Skip to content

Commit af47ba7

Browse files
committed
memory leak fix
1 parent 742873d commit af47ba7

File tree

3 files changed

+16
-99
lines changed

3 files changed

+16
-99
lines changed

src/main/kotlin/com/lambda/interaction/request/breaking/BreakInfo.kt

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ import com.lambda.interaction.request.breaking.BreakInfo.BreakType.Secondary
2828
import com.lambda.interaction.request.breaking.BreakManager.calcBreakDelta
2929
import com.lambda.util.Describable
3030
import com.lambda.util.NamedEnum
31-
import com.lambda.util.OneSetPerTick
3231
import net.minecraft.client.network.ClientPlayerEntity
3332
import net.minecraft.client.network.ClientPlayerInteractionManager
3433
import net.minecraft.client.world.ClientWorld
@@ -48,25 +47,23 @@ data class BreakInfo(
4847

4948
// Pre Processing
5049
var shouldProgress = false
51-
var rebreakPotential by OneSetPerTick(value = RebreakHandler.RebreakPotential.None, throwOnLimitBreach = true).linkLifetime()
52-
var swapInfo by OneSetPerTick(value = SwapInfo.EMPTY, throwOnLimitBreach = true).linkLifetime()
53-
var swapStack: ItemStack by OneSetPerTick(ItemStack.EMPTY, true).linkLifetime()
50+
var rebreakPotential = RebreakHandler.RebreakPotential.None
51+
var swapInfo = SwapInfo.EMPTY
52+
var swapStack: ItemStack = ItemStack.EMPTY
5453

5554
// BreakInfo Specific
56-
var updatedThisTick by OneSetPerTick(false, resetAfterTick = true).apply { set(true) }.linkLifetime()
57-
var updatedPreProcessingThisTick by OneSetPerTick(value = false, throwOnLimitBreach = true, resetAfterTick = true).linkLifetime()
58-
var progressedThisTick by OneSetPerTick(value = false, throwOnLimitBreach = true, resetAfterTick = true).linkLifetime()
55+
var updatedThisTick = true
56+
var updatedPreProcessingThisTick = false
57+
var progressedThisTick = false
5958

6059
// Processing
6160
var breaking = false
6261
var abandoned = false
63-
var breakingTicks by OneSetPerTick(0, true).linkLifetime()
64-
var soundsCooldown by OneSetPerTick(0f, true).linkLifetime()
62+
var breakingTicks = 0
63+
var soundsCooldown = 0f
6564
var vanillaInstantBreakable = false
6665
val rebreakable get() = !vanillaInstantBreakable && type == Primary
6766

68-
val oneSetPerTickSet = mutableSetOf<OneSetPerTick<*>>()
69-
7067
enum class BreakType(
7168
override val displayName: String,
7269
override val description: String
@@ -109,6 +106,12 @@ data class BreakInfo(
109106
item = null
110107
}
111108

109+
fun tickChecks() {
110+
updatedThisTick = false
111+
updatedPreProcessingThisTick = false
112+
progressedThisTick = false
113+
}
114+
112115
fun setBreakingTextureStage(
113116
player: ClientPlayerEntity,
114117
world: ClientWorld,
@@ -175,7 +178,4 @@ data class BreakInfo(
175178
}
176179

177180
override fun toString() = "$type, ${context.cachedState}, ${context.blockPos}"
178-
179-
private fun <T : Any> OneSetPerTick<T>.linkLifetime() =
180-
apply { oneSetPerTickSet.add(this) }
181181
}

src/main/kotlin/com/lambda/interaction/request/breaking/BreakManager.kt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ import com.lambda.util.BlockUtils.calcItemBlockBreakingDelta
7777
import com.lambda.util.BlockUtils.isEmpty
7878
import com.lambda.util.BlockUtils.isNotBroken
7979
import com.lambda.util.BlockUtils.isNotEmpty
80-
import com.lambda.util.OneSetPerTick
8180
import com.lambda.util.extension.partialTicks
8281
import com.lambda.util.item.ItemUtils.block
8382
import com.lambda.util.math.lerp
@@ -173,6 +172,7 @@ object BreakManager : RequestHandler<BreakRequest>(
173172
}
174173

175174
listen<TickEvent.Post>(priority = Int.MIN_VALUE) {
175+
breakInfos.forEach { it?.tickChecks() }
176176
if (breakCooldown > 0) {
177177
breakCooldown--
178178
}
@@ -640,13 +640,11 @@ object BreakManager : RequestHandler<BreakRequest>(
640640
/**
641641
* Nullifies the break. If the block is not broken, the [BreakInfo.internalOnCancel] callback gets triggered
642642
*/
643-
private fun BreakInfo.nullify() {
643+
private fun BreakInfo.nullify() =
644644
when (type) {
645645
Primary, Rebreak -> primaryBreak = null
646646
else -> secondaryBreak = null
647647
}
648-
oneSetPerTickSet.forEach(OneSetPerTick<*>::destroy)
649-
}
650648

651649
/**
652650
* A modified version of the vanilla updateBlockBreakingProgress method.

src/main/kotlin/com/lambda/util/OneSetPerTick.kt

Lines changed: 0 additions & 81 deletions
This file was deleted.

0 commit comments

Comments
 (0)