I’m attempting to finish up the C++ editor that scorvi put out. I added the ability to delete nodes, but it crashes when one node is a child of another and both are being deleted.
The angelscript version works as follows:
// Remove nodes
for (uint i = 0; i < selectedNodes.length; ++i)
{
Node@ node = selectedNodes[i];
if (node.parent is null || node.scene is null)
continue; // Root or already deleted
uint nodeIndex = GetListIndex(node);
// Create undo action
DeleteNodeAction action;
action.Define(node);
group.actions.Push(action);
node.Remove();
SetSceneModified();
// If deleting only one node, select the next item in the same index
if (selectedNodes.length == 1 && selectedComponents.empty)
hierarchyList.selection = nodeIndex;
}
And my code in C++:
Urho3D::Vector<Urho3D::Node*> nodes = _editorSelection->GetSelectedNodes();
for (unsigned int i = 0; i < nodes.Size(); i++)
{
Urho3D::Node* node = nodes[i];
if (!node->GetParent() || !node->GetScene())
continue;
node->Remove();
}
The crash appears to be caused by a bad pointer held by the child node. The parent node is already removed, and the child node’s parent_ pointer points to 0xfeeefeee instead of being null (This is a Visual Studio value). AFAIK the angelscript bindings uses the Node’s GetParent/SetParent methods. Does anyone see a problem with my approach?