|
写了一个更新回调,operator()中的操作就是向root添加子节点
每次运行到这里就崩溃了
- class CCtrSceneCallback : public osg::NodeCallback
- {
- public:
- CCtrSceneCallback()
- : _ctrNode(0)
- // , _childNode(NULL)
- {
- _childNode = new osg::Node();
- }
- virtual void operator()( osg::Node* node,osg::NodeVisitor* nv )
- {
- if (_ctrNode > 0)
- {
- osg::Group* root = dynamic_cast<osg::Group*> (node);
- if (_ctrNode == 1)
- {
- root->addChild(_childNode);
- }
- else if (_ctrNode == 2)
- {
- root->removeChild(_childNode);
- }
- _ctrNode = 0;
- }
- // 继续遍历节点
- traverse( node, nv );
- }
- void setChildNode(osg::Node* child,int mode)
- {
- _childNode = child;
- _ctrNode = mode;
- }
- protected:
- osg::Node* _childNode;
- int _ctrNode;
- };
复制代码
在外部通过调用void setChildNode(osg::Node* child,int mode)
更改_childNode,并控制_ctrNode
结果每次运行到root->addChild(_childNode);程序都中断 |
|