From 6baa932c32fe15fbdc0cac73dfc64cd9ccaa9357 Mon Sep 17 00:00:00 2001 From: Batuhan Tonga <76632145+QueryOfficial@users.noreply.github.com> Date: Sat, 4 Jul 2026 20:24:13 +0300 Subject: [PATCH] Enhance CXMLNodeImpl destructor to ensure proper node unlinking and document synchronization - Updated the destructor to first delete wrapper children, allowing each child to unlink its own tinyxml2 node before the parent is removed. - Added logic to keep the underlying document in sync when nodes are destroyed via xmlDestroyNode, ensuring m_pNode is nullified before deletion to prevent unlinking issues during document teardown. --- Shared/XML/CXMLNodeImpl.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/Shared/XML/CXMLNodeImpl.cpp b/Shared/XML/CXMLNodeImpl.cpp index cd6cd243f5..8903cb4c30 100644 --- a/Shared/XML/CXMLNodeImpl.cpp +++ b/Shared/XML/CXMLNodeImpl.cpp @@ -47,9 +47,20 @@ CXMLNodeImpl::~CXMLNodeImpl() if (m_bUsingIDs) CXMLArray::PushUniqueID(this); - // Delete our children + // Delete wrapper children first so each child unlinks its own tinyxml2 node + // before this node is removed from the document. DeleteAllSubNodes(); + // Keep the underlying document in sync when nodes are destroyed via + // xmlDestroyNode. DeleteWrapper nulls m_pNode before delete to avoid + // unlinking during full file teardown. + if (m_pNode) + { + if (XMLNode* pXmlParent = m_pNode->Parent()) + pXmlParent->DeleteChild(m_pNode); + m_pNode = nullptr; + } + // We need a parent to delete the node if (m_pParent) {