Re: [osg-users] dynamic_cast of referenced objects
Hi, For anyone who is still following this thread (or for anyone who stumbles upon it while trying to solve a similar problem in the future), I figured I'd post my findings: The bit about the object reference pointers vs. standard C++ pointers turned out to be a red herring. Seems the crashes resulted from my method of updating 2D text in the scene. I was just calling -settext(blah) from the main loop whenever I wanted to change the displayed characters. The crashes went away when I implemented a callback function to update the text. Here's an example of my text update callback function: Code: struct TextUpdateCallback : public osg::Drawable::UpdateCallback { virtual void update(osg::NodeVisitor* nv, osg::Drawable* drawable) { osgText::Text * TextPointer = dynamic_castosgText::Text*(drawable) ; if ( TextPointer ) { TextPointer-setText(NewText) ; TextPointer-setColor(NewColour) ; } } } I hope this helps. Cheers, Kevin[/quote] -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=23879#23879 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] dynamic_cast of referenced objects
Hi, Thank you both for all of your help! Cheers, Kevin -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=23805#23805 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
[osg-users] dynamic_cast of referenced objects
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_castosg::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_ptrosg::node into an osg::ref_ptrosg::MatrixTransform when using referenced object pointers? I'm trying to do something like: --- snip --- void operator()( osg::ref_ptrosg::Node node, osg::ref_ptrosg::NodeVisitor nv ) { osg::ref_ptrosg::MatrixTransform MatrixXform = dynamic_castosg::ref_ptrosg::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 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] How to name the viewer window???
Hi, I came upon this post while searching for a way to do exactly the same thing. Now that I've found a solution, I thought I would post it for the benefit of everyone on this forum: // create the windows and start the required threads. viewer.realize(); // add a caption to the viewer window osgViewer::Viewer::Windows ViewerWindow; viewer.getWindows(ViewerWindow); if (!ViewerWindow.empty()) { ViewerWindow.front()-setWindowName( MyCaption ); } // Get windows handle for viewer window and set the viewer window icon hWnd = FindWindow(NULL, _T(MyCaption ); HANDLE hIcon = LoadImage(0, MyIcon.ico, IMAGE_ICON, 0, 0, LR_LOADFROMFILE); if( hIcon hWnd ) { SendMessage(hWnd, WM_SETICON, ICON_SMALL, (LPARAM)hIcon); } Cheers, Kevin -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=21372#21372 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org