From 4f1411b005859a510fe8d8f1af8db9b848dd4454 Mon Sep 17 00:00:00 2001 From: MihailRis Date: Sat, 26 Sep 2026 19:51:08 +0300 Subject: [PATCH 1/2] fix infinite recursion on moveInto used to move to descendant node --- src/graphics/ui/elements/UINode.cpp | 4 ++-- src/graphics/ui/elements/UINode.hpp | 2 +- src/logic/scripting/lua/libs/libgui.cpp | 7 +++++++ 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/graphics/ui/elements/UINode.cpp b/src/graphics/ui/elements/UINode.cpp index 85347b9a8..918d30b65 100644 --- a/src/graphics/ui/elements/UINode.cpp +++ b/src/graphics/ui/elements/UINode.cpp @@ -376,14 +376,14 @@ void UINode::setGravity(Gravity gravity) { } } -bool UINode::isSubnodeOf(const UINode* node) { +bool UINode::isDescendantOf(const UINode* node) { if (parent == nullptr) { return false; } if (parent == node) { return true; } - return parent->isSubnodeOf(node); + return parent->isDescendantOf(node); } void UINode::getIndices( diff --git a/src/graphics/ui/elements/UINode.hpp b/src/graphics/ui/elements/UINode.hpp index a7b18390c..4f6145f08 100644 --- a/src/graphics/ui/elements/UINode.hpp +++ b/src/graphics/ui/elements/UINode.hpp @@ -290,7 +290,7 @@ namespace gui { virtual void setGravity(Gravity gravity); - bool isSubnodeOf(const UINode* node); + bool isDescendantOf(const UINode* node); /// @brief collect all nodes having id static void getIndices( diff --git a/src/logic/scripting/lua/libs/libgui.cpp b/src/logic/scripting/lua/libs/libgui.cpp index 389bedc9a..dc4806d00 100644 --- a/src/logic/scripting/lua/libs/libgui.cpp +++ b/src/logic/scripting/lua/libs/libgui.cpp @@ -165,6 +165,13 @@ static int l_container_set_interval(lua::State* L) { static int l_move_into(lua::State* L) { auto node = get_document_node(L, 1); auto dest = get_document_node(L, 2); + if (dest.node == nullptr) { + return 0; + } + if (dest.node->isDescendantOf(node.node.get())) { + luaL_error(L, "unable to move element to its descendant"); + return 0; + } UINode::moveInto( node.node, std::dynamic_pointer_cast(dest.node) ); From c3b50b5ab2ebc88719e25f8964d70a4f389e389f Mon Sep 17 00:00:00 2001 From: MihailRis Date: Sat, 26 Sep 2026 20:28:20 +0300 Subject: [PATCH 2/2] fix recursive iframe --- src/graphics/ui/elements/InlineFrame.cpp | 6 +++++- src/graphics/ui/elements/UINode.cpp | 4 ++++ src/graphics/ui/elements/UINode.hpp | 1 + 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/graphics/ui/elements/InlineFrame.cpp b/src/graphics/ui/elements/InlineFrame.cpp index eeef50e47..8699fd70b 100644 --- a/src/graphics/ui/elements/InlineFrame.cpp +++ b/src/graphics/ui/elements/InlineFrame.cpp @@ -25,8 +25,12 @@ void InlineFrame::setDocument(const std::shared_ptr& document) { if (document == nullptr) { return; } + auto newRoot = document->getRoot(); + if (newRoot->hasParent()) { + return; + } this->document = document; - this->root = document->getRoot(); + this->root = std::move(newRoot); add(root); root->setSize(size); diff --git a/src/graphics/ui/elements/UINode.cpp b/src/graphics/ui/elements/UINode.cpp index 918d30b65..3f099d2b8 100644 --- a/src/graphics/ui/elements/UINode.cpp +++ b/src/graphics/ui/elements/UINode.cpp @@ -60,6 +60,10 @@ bool UINode::isHover() const { return hover; } +bool UINode::hasParent() const { + return parent != nullptr; +} + void UINode::setParent(UINode* node) { parent = node; } diff --git a/src/graphics/ui/elements/UINode.hpp b/src/graphics/ui/elements/UINode.hpp index 4f6145f08..f22487323 100644 --- a/src/graphics/ui/elements/UINode.hpp +++ b/src/graphics/ui/elements/UINode.hpp @@ -176,6 +176,7 @@ namespace gui { void setMouseOver(bool flag); virtual void setParent(UINode* node); + bool hasParent() const; UINode* getParent() const; std::shared_ptr getParentShared() const;