eugene.litvinov Posted March 29, 2011 Share Posted March 29, 2011 I have world file with some node's hierarchy, for example:I need to delete cube_white_0 node with all it's children (via game mode, not from Unigine editor).I try use engine.editor.removeNode(child) - this delete only cube_white_0 but it's children stays in world.I try use ::node_remove(child); - this case an error: Variable::removeExternClass(): object is not constructed Link to comment
ulf.schroeter Posted March 29, 2011 Share Posted March 29, 2011 I have world file with some node's hierarchy, for example: I need to delete cube_white_0 node with all it's children (via game mode, not from Unigine editor). I try use engine.editor.removeNode(child) - this delete only cube_white_0 but it's children stays in world. I try use ::node_remove(child); - this case an error: Variable::removeExternClass(): object is not constructed Have a look into documentation Programming\Memory Management" and Programming\High-Level-Scripts\Basisc Utilities\Unigine Script for details. removeNode only removes ownership, but does not delete the node and therefore causes memory leaks. I think if the node belongs to editor you first have to revoke editor ownership, than transfer ownership to script and finally call node_delete() Node node = engine.editor.getNodeByName("cube_white_0"); if( node != 0 ) { engine.editor.releaseNode( node ); // release editor ownership node_append( node ); // set script ownership node_delete( node ); // delete node and its childs } Link to comment
eugene.litvinov Posted March 30, 2011 Author Share Posted March 30, 2011 I'm looking into documentation from time to time... but ownerships, managements and casting nodes it's Houdini's magic for my :) Link to comment
ulf.schroeter Posted March 30, 2011 Share Posted March 30, 2011 but ownerships, managements and casting nodes it's Houdini's magic for my :) right, not an easy topic in UNIGINE. Have you tested above code snippet ? Does it work ? Link to comment
eugene.litvinov Posted March 30, 2011 Author Share Posted March 30, 2011 Yes, thanks, nodes removed with all children, but if I try to load different world after this, I have crash of Unigine, and any line in log about it ( If I comment this lines: engine.editor.releaseNode(child); // release editor ownership node_append(child); // set script ownership node_delete(child); // delete node and its childs all good, if uncomment and call engine.console.run("world_load source/maps/different_map"); I have crash Link to comment
ulf.schroeter Posted March 30, 2011 Share Posted March 30, 2011 You should provide smallest possible test case (e.g. two small world files with nodes to delete and test.cpp script) for problem reproduction. Link to comment
eugene.litvinov Posted March 30, 2011 Author Share Posted March 30, 2011 You should provide smallest possible test case (e.g. two small world files with nodes to delete and test.cpp script) for problem reproduction. Good proposition. I do some tests and find, that crash occurs only when I add node inside of NodeReference (in Editor), if I use "clean" NodeReference - all good. Seems like bug, on the assumption of it right way to delete existing nodes. Anyway, I will use NodeReference without any added child inside it, so it ok :) Link to comment
binstream Posted March 30, 2011 Share Posted March 30, 2011 I'm looking into documentation from time to time... but ownerships, managements and casting nodes it's Houdini's magic for my :( Please point out hard to understand parts of the documentation and we'll improve them. Link to comment
eugene.litvinov Posted March 30, 2011 Author Share Posted March 30, 2011 Please point out hard to understand parts of the documentation and we'll improve them. My confuse not because of documentation, it difficult for understanding, for example, why for remove node I need release it from editor, add to script and delete from script? engine.editor.releaseNode(child); // release editor ownership node_append(child); // set script ownership node_delete(child); // delete node and its childs I expected that I can remove node with all it children by, for example, function engine.editor.removeNode(child), IMHO. Link to comment
ulf.schroeter Posted March 30, 2011 Share Posted March 30, 2011 I expected that I can remove node with all it children by, for example, function engine.editor.removeNode(child), IMHO. removal != delete Link to comment
eugene.litvinov Posted March 30, 2011 Author Share Posted March 30, 2011 removal != delete If I remove object from world hierarchy, then garbage collector deletes it cause we have no more links on object, it doesn't? Link to comment
ulf.schroeter Posted March 30, 2011 Share Posted March 30, 2011 If I remove object from world hierarchy, then garbage collector deletes it cause we have no more links on object, it doesn't? see post at top: Have a look into documentation Programming\Memory Management" and Programming\High-Level-Scripts\Basisc Utilities\Unigine Script for details. removeNode only removes ownership, but does not delete the node and therefore causes memory leaks. Link to comment
eugene.litvinov Posted April 1, 2011 Author Share Posted April 1, 2011 I have some additional problem with NodeReference: I have some objects in my world file (their type is NodeReference) I use int intersectionResult[0]; Object selectedNode = engine.world.getIntersection(actorPos, actorFeelerPos, ~0, intersectionResult); to get an node, that I need to delete. When I get intersection object, it is a inner NodeReference node, so I need to get exactly NodeReference to delete it. I do next: NodeReference node = Utils::getReference(object); LOG("NodeReference = " + node.getName()); - - - - namespace Utils { // get parent node - NodeReference NodeReference getReference(Node node) { while (node != NULL) { log.message("Node = " + node.getName() + ", " + typeinfo(node.getParent())); if (node.getType() == NODE_REFERENCE) return node; node = node.getParent(); } return NULL; } } And I have next trace: Node = cube_green, Node 0000000000000000 external (55:396:396) and error, that returned node is NULL. How can I get NodeReference pointer to delete it? Thanks Link to comment
ulf.schroeter Posted April 1, 2011 Share Posted April 1, 2011 A NodeReference referencing a Node is NOT the parent of the node. Therefore you get NULL. Possible brute force solution for your problem might be Node getReference( Node referencedNode ) { int numNodes = engine.editor.getNumNodes(); for( int i=0; i<numNodes; i++ ) { Node node = engine.editor.getNode(i); if( node.getType() == NODE_REFERENCE ) { NodeReference reference = node; if( reference.getNode() == referencedNode ) { return reference; } } } return NULL; } Link to comment
mandee.cabato.ph Posted May 3, 2012 Share Posted May 3, 2012 Normally, if I want to delete a node that is in or has been added to the editor node list, I do it this way: engine.editor.releaseNode(node); class_append(node); delete node; Link to comment
manguste Posted May 6, 2012 Share Posted May 6, 2012 Eugene, nodes inside the node ref hierarchy do not know anything about the node reference they are contained in. Ulf is right, the root returns NULL as its parent. A function was added in the last SDK update just for cases like yours: Node::getNodeReference(). Link to comment
Recommended Posts