> I am working on a function that incorporates the replaceChild 
> function to replace a node, but my program keeps faulting out 
> in VisualStudio .NET file free.c with the error message 
> "Unhandled exception at 0x0040fc74 in Interactive 
> Architecture.exe: 0xC0000005: Access violation reading 
> location 0xabababab."  

What line of YOUR code is in the call stack when the crash occurs?

0xabababab is suspicious, but I don't remember what it means, perhaps your
accessing uninitialized or deleted memory.

Other notes below:

> I am new to OSG and am having problems pin-pointing my problem.
> 
> The code is as follows:
> class ToolReplaceNode: public FileSelTool {            
> //attempt to create .txt file by Catherine Peloquin 5-31-07 
> public:
>     ToolReplaceNode():FileSelTool("replacenode") {}
>     virtual void fileSelected(const char *n) {
>         const std::string name = n;
>         //osg::Node* new_node = osgDB::readNodeFile(name); 
>         osg::ref_ptr<SceneGraph> sceneGraph;
>         sceneGraph.get();

I'm not sure what the above two lines of code are for. Try removing them.

>         osg::Node *new_node = osgDB::readNodeFile(name);
>         osg::Node *old_node = dynamic_cast<osg::Node 
> *>(editor->getSelected()); 
>         osg::Group *parent=(old_node->asGroup())->getParent(1);

Don't need asGroup() here, because Node has the getParent() interface. But
you are asking for parent index 1, which assumes there are two parents.
Double-check that by calling getNumParents(). So, I'd rewrite this as:
    osg::Group *parent( NULL );
    If (old_node->getNumParents() >= 2)
        parent=old_node->getParent(1);

Or, if you meant index 0 instead of index 1:
    osg::Group *parent( NULL );
    If (old_node->getNumParents() >= 1)
        parent=old_node->getParent(0);

Another thing you can do is get in the habit of littering debug info into
your code using the Notify class:
    if (parent==NULL)
        osg::notify( osg::FATAL ) << "Null parent" << std::endl;
That way, you get errors dumped to your console window just before things
crash.

>         parent->replaceChild(old_node, new_node);
> 
>     }
>     virtual Tool* clone() { return new ToolReplaceNode(); } };
> 
> 
> I will break this into a .cxx and a .h, but just want it to 
> run first.  I am using Visual Studio as a compiler.
> 
> Does anyone have any suggestions?
> 
> Thanks,
> Catherine Peloquin
> 
> 

_______________________________________________
osg-users mailing list
[email protected]
http://openscenegraph.net/mailman/listinfo/osg-users
http://www.openscenegraph.org/

Reply via email to