I have a ScrollView with nested layouts, buttons, and other scrolls.
When I trying to delete from scene this ScrollView (verticalScroll->removeFromParentAndCleanup(true) time-to-time I have random crash inside renderer code or inside this fuction (void Node::visit(Renderer* renderer, const Mat4 &parentTransform, uint32_t parentFlags)) when it’s trying to iterate _children.
Even when deleting from the scene was successful and I try to create new ScrollView with nested objects it is not rendering on the scene anymore.
I am using cocos2d-x-3.17.1
Please Help!
Small Update: Deleting and regenerating starting on CallBack from an external library. I made code for testing what do the same by a button click and it works fine.
One posible soluttion is to rise flag in callback for regenerate UI elements and check it on scene update and call code for regenerating UI on the update
If it’s working in a Node::update(), then the most likely cause of your crash is that you were removing nodes from a separate thread while they were still in use during a rendering cycle. You can only remove items in the UI thread, and as you noticed, in the update cycle.
You can still use your callback from the external library if you want, but you would need to do something like this:
void callback()
{
cocos2d::Director::getInstance()->getScheduler()->performFunctionInCocosThread([](){
// Your node removal goes here. If this still causes any issues, then you will need to
// call scheduleOnce([](){ ... node removal code in here... }) to schedule a single update that
// removes the nodes, which is equivalent to placing the code in the Node::update, but without
// cluttering your Node::update() method with conditional checks and irrelevant code
}
}