Problem iterating over Subnodes of VrmlData_Group

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

gkv311 n's picture
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.

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.

Joachim Greiner's picture

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.
}
}
}