nathank Posted January 12, 2012 Share Posted January 12, 2012 I'm creating a bunch of boxes at runtime using the create_box function in data\samples\common\physics.h. At some point I want to completely destroy these boxes but every way I attempt to do this it seems to just crash the engine. I've read the Memory Management section in the help (many many times) and based on that, and the code I see in the create_box function, I would have thought I could remove the objects using something like engine.editor.removeNode(body_returned_from_create_box.getObject()) but that doesn't work. I can see the objects in the editor node window, and manually delete them in there with no problem. I've also tried various other things like removing the objects from the editor (editor.engine.removeNode), and changing the ownership (class_remove, class_append) before I attempt to delete but to no avail. It's worth noting that I am also creating joints between the bodies, which I create with class_remove(new JointPrismatic(body1, body2)), and adding a frozen callback which I'm clearing before I attempt to delete the object with setFrozenCallback(NULL). So what really is the correct way to delete objects created by those sample physics functions, and should I take extra steps to remove the joints before deleting the objects? Link to comment
carl.sutton Posted January 12, 2012 Share Posted January 12, 2012 I can add physics primitives, add joints to them and editor remove them without crashing. Just a hunch, maybe you could try using a function like; void remove_node(Node node) { if(engine.editor.isNode(node)) { for(int i = node.getNumChilds() - 1; i >= 0; i--) { remove_node(node.getChild(i)); } int ret = 0; ret = engine.editor.removeNode(node); assert(ret == 1); } } That will ensure you delete all child nodes if they are parented. Link to comment
nathank Posted January 15, 2012 Author Share Posted January 15, 2012 Problem solved. I was trying to delete the boxes in flush. Works correctly if I do it in update instead. Link to comment
manguste Posted January 31, 2012 Share Posted January 31, 2012 Just in case: see Where to Put Your Code: Update(), Flush() or Render() for tips :) Link to comment
Recommended Posts