![]() |
![]() |
|
|||||||
| Open Inventor Main Forum General discussions about Open Inventor from VSG |
![]() |
|
|
Thread Tools | Display Modes |
|
#1
|
|||
|
|||
|
Hi Mike,
I have created a new accumulated element for my own node e.g. SoMyNode. I have one renderer, which will be using this element. I want to add the information to element during SoMyNode traversal. i have the following queries: 1. can I add the instance of SoMyNode to Element directly. if i create a new variable in my element e.g. sbPList. 2. Will it create some issues? I am providing some code Code:
class MyElement : public SoAccumulatedElement
{
static void add(SoState *state, SoNode *node, SoNode *node)
{
..........
nodes.append(node);
}
private:
SbPList nodes;
};
class SoMyNode : public SoNode
{
void GLRender(SoGLRenderAction *ac) {
MyElement::add(ac->getState(),this,this);
}
}
class MyRenderer
{
void GLRender(SoGLRenderAction *ac) {
MyElement *element = MyElement::getInstance(ac->getState());
}
}
__________________
Thanks and Best Regards, Aman |
|
#2
|
|||
|
|||
|
Hello,
You can store some nodes in elements only if you are sure that these nodes will not be destroyed before the Open Inventor state. In fact, is a node is destroyed or removed from the scene, the Open Inventor is not necessarily rebuilt, thus, at the next traversal, application will crash because of bad node access. A solution can be implemented to manage this problem, but we clearly not recommend it (but possible since OIV 9.0.1. It consists in adding an auditor to the stored nodes so that nodes deletion is tracked throught the dyingReference() virtual method call. As an example: Code:
class MyElement : public SoAccumulatedElement
{
static void add(SoState *state, SoNode *node, SoNode *node)
{
..........
nodes.append(node);
node->addAuditor(this, SoNotRec::ELEMENT);
}
MyElement::~MyElement()
{
for (int i=0;i<nodes.size();++i)
{
if ( nodes[i] != NULL )
nodes[i]->removeAuditor(this,SoNotRec::ELEMENT);
}
}
virtual void MyElement::dyingReference()
{
// A node as been destroyed... cleanup the list...
for (int i=0;i<nodes.size();++i)
{
if ( nodes[i] != NULL )
nodes[i]->removeAuditor(this,SoNotRec::ELEMENT);
}
nodes.clear();
}
private:
SbPList nodes;
};
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|