internal static uint DepthFirstOnChildRemoving(RenderChain renderChain, VisualElement ve)
        {
            // Recurse on children
            int  childrenCount = ve.hierarchy.childCount - 1;
            uint deepCount     = 0;

            while (childrenCount >= 0)
            {
                deepCount += DepthFirstOnChildRemoving(renderChain, ve.hierarchy[childrenCount--]);
            }

            if (ve.renderChainData.isInChain)
            {
                renderChain.ChildWillBeRemoved(ve);
                CommandGenerator.ResetCommands(renderChain, ve);
                renderChain.ResetTextures(ve);
                ve.renderChainData.isInChain  = false;
                ve.renderChainData.clipMethod = ClipMethod.Undetermined;

                if (ve.renderChainData.next != null)
                {
                    ve.renderChainData.next.renderChainData.prev = ve.renderChainData.prev;
                }
                if (ve.renderChainData.prev != null)
                {
                    ve.renderChainData.prev.renderChainData.next = ve.renderChainData.next;
                }

                if (RenderChainVEData.AllocatesID(ve.renderChainData.textCoreSettingsID))
                {
                    renderChain.shaderInfoAllocator.FreeTextCoreSettings(ve.renderChainData.textCoreSettingsID);
                    ve.renderChainData.textCoreSettingsID = UIRVEShaderInfoAllocator.defaultTextCoreSettings;
                }
                if (RenderChainVEData.AllocatesID(ve.renderChainData.opacityID))
                {
                    renderChain.shaderInfoAllocator.FreeOpacity(ve.renderChainData.opacityID);
                    ve.renderChainData.opacityID = UIRVEShaderInfoAllocator.fullOpacity;
                }
                if (RenderChainVEData.AllocatesID(ve.renderChainData.colorID))
                {
                    renderChain.shaderInfoAllocator.FreeColor(ve.renderChainData.colorID);
                    ve.renderChainData.colorID = BMPAlloc.Invalid;
                }
                if (RenderChainVEData.AllocatesID(ve.renderChainData.backgroundColorID))
                {
                    renderChain.shaderInfoAllocator.FreeColor(ve.renderChainData.backgroundColorID);
                    ve.renderChainData.backgroundColorID = BMPAlloc.Invalid;
                }
                if (RenderChainVEData.AllocatesID(ve.renderChainData.borderLeftColorID))
                {
                    renderChain.shaderInfoAllocator.FreeColor(ve.renderChainData.borderLeftColorID);
                    ve.renderChainData.borderLeftColorID = BMPAlloc.Invalid;
                }
                if (RenderChainVEData.AllocatesID(ve.renderChainData.borderTopColorID))
                {
                    renderChain.shaderInfoAllocator.FreeColor(ve.renderChainData.borderTopColorID);
                    ve.renderChainData.borderTopColorID = BMPAlloc.Invalid;
                }
                if (RenderChainVEData.AllocatesID(ve.renderChainData.borderRightColorID))
                {
                    renderChain.shaderInfoAllocator.FreeColor(ve.renderChainData.borderRightColorID);
                    ve.renderChainData.borderRightColorID = BMPAlloc.Invalid;
                }
                if (RenderChainVEData.AllocatesID(ve.renderChainData.borderBottomColorID))
                {
                    renderChain.shaderInfoAllocator.FreeColor(ve.renderChainData.borderBottomColorID);
                    ve.renderChainData.borderBottomColorID = BMPAlloc.Invalid;
                }
                if (RenderChainVEData.AllocatesID(ve.renderChainData.tintColorID))
                {
                    renderChain.shaderInfoAllocator.FreeColor(ve.renderChainData.tintColorID);
                    ve.renderChainData.tintColorID = BMPAlloc.Invalid;
                }
                if (RenderChainVEData.AllocatesID(ve.renderChainData.clipRectID))
                {
                    renderChain.shaderInfoAllocator.FreeClipRect(ve.renderChainData.clipRectID);
                    ve.renderChainData.clipRectID = UIRVEShaderInfoAllocator.infiniteClipRect;
                }
                if (RenderChainVEData.AllocatesID(ve.renderChainData.transformID))
                {
                    renderChain.shaderInfoAllocator.FreeTransform(ve.renderChainData.transformID);
                    ve.renderChainData.transformID = UIRVEShaderInfoAllocator.identityTransform;
                }
                ve.renderChainData.boneTransformAncestor = ve.renderChainData.groupTransformAncestor = null;
                if (ve.renderChainData.closingData != null)
                {
                    renderChain.device.Free(ve.renderChainData.closingData);
                    ve.renderChainData.closingData = null;
                }
                if (ve.renderChainData.data != null)
                {
                    renderChain.device.Free(ve.renderChainData.data);
                    ve.renderChainData.data = null;
                }
            }
            return(deepCount + 1);
        }