diff --git a/cocos/ui/UIRichText.cpp b/cocos/ui/UIRichText.cpp index 7fac871a00..c32489b8b1 100644 --- a/cocos/ui/UIRichText.cpp +++ b/cocos/ui/UIRichText.cpp @@ -178,7 +178,7 @@ void RichText::formatText() { if (_formatTextDirty) { - this->removeAllChildren(); + this->removeAllProtectedChildren(); _elementRenders.clear(); if (_ignoreSize) { @@ -353,7 +353,7 @@ void RichText::formarRenderers() Node* l = row->at(j); l->setAnchorPoint(Vec2::ZERO); l->setPosition(nextPosX, 0.0f); - this->addChild(l, 1); + this->addProtectedChild(l, 1); Size iSize = l->getContentSize(); newContentSizeWidth += iSize.width; newContentSizeHeight = MAX(newContentSizeHeight, iSize.height); @@ -391,7 +391,7 @@ void RichText::formarRenderers() Node* l = row->at(j); l->setAnchorPoint(Vec2::ZERO); l->setPosition(nextPosX, nextPosY); - this->addChild(l, 1); + this->addProtectedChild(l, 1); nextPosX += l->getContentSize().width; } } diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIRichTextTest/UIRichTextTest.cpp b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIRichTextTest/UIRichTextTest.cpp index 8efb7e33fd..93d0d11661 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIRichTextTest/UIRichTextTest.cpp +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIRichTextTest/UIRichTextTest.cpp @@ -93,6 +93,9 @@ bool UIRichTextTest::init() _widget->addChild(_richText); + // test remove all children, this call won't effect the test + _richText->removeAllChildren(); + return true; } return false;