Detect cyclic parent references

This commit is contained in:
DBotThePony 2022-09-28 19:33:17 +07:00
parent 5d8147a8f9
commit 93b3a01ee4
Signed by: DBot
GPG Key ID: DCC23B5715498507

View File

@ -3,6 +3,7 @@ package ru.dbotthepony.mc.otm.client.screen.panels
import com.google.common.collect.ImmutableList import com.google.common.collect.ImmutableList
import com.mojang.blaze3d.systems.RenderSystem import com.mojang.blaze3d.systems.RenderSystem
import com.mojang.blaze3d.vertex.PoseStack import com.mojang.blaze3d.vertex.PoseStack
import it.unimi.dsi.fastutil.objects.ObjectArraySet
import net.minecraft.client.gui.Font import net.minecraft.client.gui.Font
import net.minecraft.client.gui.components.events.GuiEventListener import net.minecraft.client.gui.components.events.GuiEventListener
import net.minecraft.client.gui.screens.Screen import net.minecraft.client.gui.screens.Screen
@ -71,6 +72,18 @@ open class EditablePanel<out S : Screen> @JvmOverloads constructor(
if (field === value) if (field === value)
return 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?.onUnParent(this)
field = value field = value
layoutInvalidated = true layoutInvalidated = true