Detect cyclic parent references
This commit is contained in:
parent
5d8147a8f9
commit
93b3a01ee4
@ -3,6 +3,7 @@ package ru.dbotthepony.mc.otm.client.screen.panels
|
||||
import com.google.common.collect.ImmutableList
|
||||
import com.mojang.blaze3d.systems.RenderSystem
|
||||
import com.mojang.blaze3d.vertex.PoseStack
|
||||
import it.unimi.dsi.fastutil.objects.ObjectArraySet
|
||||
import net.minecraft.client.gui.Font
|
||||
import net.minecraft.client.gui.components.events.GuiEventListener
|
||||
import net.minecraft.client.gui.screens.Screen
|
||||
@ -71,6 +72,18 @@ open class EditablePanel<out S : Screen> @JvmOverloads constructor(
|
||||
if (field === value)
|
||||
return
|
||||
|
||||
val set = ObjectArraySet<EditablePanel<*>>()
|
||||
set.add(this)
|
||||
var parent = value
|
||||
|
||||
while (parent != null) {
|
||||
if (set.add(parent)) {
|
||||
parent = parent.parent
|
||||
} else {
|
||||
throw IllegalStateException("Cyclic parent reference detected: ${set.joinToString(", ") { "$it<${it::class.qualifiedName}>" }}")
|
||||
}
|
||||
}
|
||||
|
||||
field?.onUnParent(this)
|
||||
field = value
|
||||
layoutInvalidated = true
|
||||
|
Loading…
Reference in New Issue
Block a user