Random crash on removeFromParentAndCleanup

I have a problem!

I have a ScrollView with nested layouts, buttons, and other scrolls.

When I trying to delete from scene this ScrollView (verticalScroll->removeFromParentAndCleanup(true):wink: 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

I think that you should show us specific code so we can see if there is a problem.

It is fixed for now.
I just start removing objects during scene::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()
        // 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
1 Like

Thanks! :slight_smile:

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.