Kevin Wilder
2010-02-06 03:07:08 UTC
Hi,
My project is throwing an occasional "unhandled win32 exception" error and I've been trying to figure out why. There is no consistency in the timing so I assume that I have a dangling pointer somewhere. (I don't have a memory leak because the memory usage shown in the Windows Task Manager is fairly constant while my code is running.)
I came upon a passage in the OpenSceneGraph Quick Start Guide that says:
"Be careful when returning the address of an object from a function. If you do this incorrectly, the ref_ptr<> storing the memory address could go out of scope before the address is placed on the return stack."
I assume that this also applies when passing referenced objects to a function... But most of the examples of callback functions that I have seen on the web all use standard C++ pointers in the function definition, rather than ref_ptr<>. For example:
--- snip ---
void operator()( osg::Node* node, osg::NodeVisitor * nv )
{
osg::MatrixTransform * MatrixXform = dynamic_cast<osg::MatrixTransform*>(node) ;
if ( MatrixXform )
--- snip ---
Thinking that this may be the source of my dangling pointer, I tried to modify my own callback function definition to use referenced object pointers per the quick start guide's recommendations. Unfortunately, I got hung up on the dynamic_cast in the code above. I can't figure out how to cast the osg::node referenced object pointer into an osg::MatrixTransform referenced object pointer.
Is there an equivalant means of casting an osg::ref_ptr<osg::node> into an osg::ref_ptr<osg::MatrixTransform> when using referenced object pointers? I'm trying to do something like:
--- snip ---
void operator()( osg::ref_ptr<osg::Node> node, osg::ref_ptr<osg::NodeVisitor> nv )
{
osg::ref_ptr<osg::MatrixTransform> MatrixXform = dynamic_cast<osg::ref_ptr<osg::MatrixTransform>(node) ;
if ( MatrixXform )
--- snip ---
Thanks for the help. I'm relatively new to OpenSceneGraph programming.
Cheers,
Kevin
------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=23753#23753
My project is throwing an occasional "unhandled win32 exception" error and I've been trying to figure out why. There is no consistency in the timing so I assume that I have a dangling pointer somewhere. (I don't have a memory leak because the memory usage shown in the Windows Task Manager is fairly constant while my code is running.)
I came upon a passage in the OpenSceneGraph Quick Start Guide that says:
"Be careful when returning the address of an object from a function. If you do this incorrectly, the ref_ptr<> storing the memory address could go out of scope before the address is placed on the return stack."
I assume that this also applies when passing referenced objects to a function... But most of the examples of callback functions that I have seen on the web all use standard C++ pointers in the function definition, rather than ref_ptr<>. For example:
--- snip ---
void operator()( osg::Node* node, osg::NodeVisitor * nv )
{
osg::MatrixTransform * MatrixXform = dynamic_cast<osg::MatrixTransform*>(node) ;
if ( MatrixXform )
--- snip ---
Thinking that this may be the source of my dangling pointer, I tried to modify my own callback function definition to use referenced object pointers per the quick start guide's recommendations. Unfortunately, I got hung up on the dynamic_cast in the code above. I can't figure out how to cast the osg::node referenced object pointer into an osg::MatrixTransform referenced object pointer.
Is there an equivalant means of casting an osg::ref_ptr<osg::node> into an osg::ref_ptr<osg::MatrixTransform> when using referenced object pointers? I'm trying to do something like:
--- snip ---
void operator()( osg::ref_ptr<osg::Node> node, osg::ref_ptr<osg::NodeVisitor> nv )
{
osg::ref_ptr<osg::MatrixTransform> MatrixXform = dynamic_cast<osg::ref_ptr<osg::MatrixTransform>(node) ;
if ( MatrixXform )
--- snip ---
Thanks for the help. I'm relatively new to OpenSceneGraph programming.
Cheers,
Kevin
------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=23753#23753