[SOLVED] Remove node from editor with all children


photo

Recommended Posts

I have world file with some node's hierarchy, for example:
post-151-0-22967500-1301407004_thumb.jpg
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 post

I have world file with some node's hierarchy, for example:

post-151-0-22967500-1301407004_thumb.jpg

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 post

I'm looking into documentation from time to time... but ownerships, managements and casting nodes it's Houdini's magic for my :)

Link to post

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 post

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 post

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 post

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 post

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 post

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 post

I expected that I can remove node with all it children by, for example, function engine.editor.removeNode(child), IMHO.

 

removal != delete

Link to post

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 post

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 post

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 post

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 post
  • 1 year later...

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 post

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 post