unigine 正确删除node节点

正确删除node节点,代码如下。

void destroyNode(NodePtr &node)
{
	while (node->getNumChildren()>0)
	{
		NodePtr temp = node->getChild(0);
		temp->grab();
		destroyNode(temp);
		node->removeChild(temp);
		temp.destroy();
	}
}
int AppWorldLogic::update() {

	if (App::get()->clearKeyState(' '))
	{
		//method 1 
		{
			NodeReferencePtr ref = NodeReference::create("nodes/2.node");
			ref->release();
			m_node = ref->getNode();
		}
		m_node->grab();

		//method 2
		//m_node = ref->detachReference();
	}
	if (App::get()->clearKeyState(','))
	{
		//method 1
		if (m_node.get())
		{
			m_node.destroy();
		}

		//method 2
		//if (m_node.get())
		//{
		//	m_node->grab();
		//	destroyNode(m_node);
		//	m_node.destroy();
		//}
	}
}

猜你喜欢

转载自blog.csdn.net/qiushangren/article/details/87071758