Sun, 01/15/2023 - 03:09
Hi,
I want to iterate over the subnodes of a VrmlData_Group
Here is my code:
std::string filename = "KR120_R2700_0.wrl";
VrmlData_Scene vrmlScene;
std::filebuf fb1;
fb1.open(filename, std::ios::in);
Standard_IStream theInput(&fb1);
vrmlScene << theInput;
fb1.close();
VrmlData_ListOfNode::Iterator iter = vrmlScene.GetIterator();
for (; iter.More(); iter.Next())
{
const Handle(VrmlData_Group) aGroupNode = Handle(VrmlData_Group)::DownCast(iter.Value());
if (aGroupNode.IsNull() == false)
{
VrmlData_ListOfNode::Iterator iter2 = aGroupNode->NodeIterator();
const Handle(VrmlData_ShapeNode) aNodeShape = Handle(VrmlData_ShapeNode)::DownCast(iter2.Value());
at this line the code crashes. It seams, that the iterators is point to a wrong adress.
}
}
The error occurs with every vrml file that I have used. Does anyone has an idea what causes the problem?
Best regards,
Joachim
Mon, 01/16/2023 - 16:17
Your code lacks
::More()
check for nested iterator, and I guess groups might be empty (hense, NULL deteference will happen). This is just a guess.Mon, 01/16/2023 - 18:56
Oh im sorry, I forgott to copy the second loop. There is the missing ::More().
Here is the complete code now:
std::string filename = "KR120_R2700_0.wrl";
VrmlData_Scene vrmlScene;
std::filebuf fb1;
fb1.open(filename, std::ios::in);
Standard_IStream theInput(&fb1);
vrmlScene << theInput;
fb1.close();
VrmlData_ListOfNode::Iterator iter = vrmlScene.GetIterator();
for (; iter.More(); iter.Next())
{
const Handle(VrmlData_Group) aGroupNode = Handle(VrmlData_Group)::DownCast(iter.Value());
if (aGroupNode.IsNull() == false)
{
VrmlData_ListOfNode::Iterator iter2 = aGroupNode->NodeIterator();
for(; iter2.More(); iter2.Next())
{
const Handle(VrmlData_ShapeNode) aNodeShape = Handle(VrmlData_ShapeNode)::DownCast(iter2.Value());
at this line the code crashes. It seams, that the iterators is point to a wrong adress.
}
}
}