Removal of objects

I’m a bit confused in what order I should remove an object where I have the following parts:
SharedPtr node;
SharedPtr model;
SharedPtr vb;
SharedPtr ib;
SharedPtr geom;
PODVector elements;
SharedPtr object;
SharedPtr shape;
SharedPtr body;

So I’ve created a model with vertexbuffers and rigidbody. At a certain point I want to remove the object. What order should I use?

I thought I could use the node->Remove(), but that crashes the program since it causes null pointers.

Any advice?

You should design your classes being able to destroy automatically. So, node->Remove() should work fine.
Ensure that you don’t keep any SharedPtr onto Nodes/Components at the moment of removal.
Usually it means that you shouldn’t keep any SharedPtr onto such objects longer than for a moment.

1 Like