Hi Enrico,
the addRefCP increments and the subRefCP decrements the ref counter. If
you call a addRefCP you should also call a subRefCP. If the refcounter
gets zero the pointer is destroyed automatically. Well if a program
terminates all memory is freed.
Andreas
Thanks Andreas,
the addRefCP did the trick.
Just to clarify a bit my mind: i added the whole bunch
of ChunkMaterials and readied 'em for the use in
the init of the application.I noticed also a
subRefCP function, which is used, i assume, to
tell opensg that some chunks are no longer on
any use in the application. Should i subRefCP
my materials before the end of the program?
I wouldn't like to keep zombies in my memory.
thanks and sorry for the lameness :)
enrico
Il mar, 2005-02-15 alle 10:49, Andreas Zieringer ha scritto:
Hi Enrico,
the ChunkMaterialPtr's are reference counted.
group->setMaterial(mat1)
group->setMaterial(mat3) // the mat1 refcounter is decremented
group->setMaterial(mat4) // the mat3 refcounter is decremented
group->setMaterial(mat4)
So after the mat4 assignment mat3 is not referenced anymore and
destroyed. After creating your materials you should increment the
reference counters with addRefCP(mat)
Andreas
hi all (and hi dirk, thx 4 the greeting in the skybgd message),
I spent the past week setting up a material parser
which loads from some xml files a collection of
materials, along with the relative shaders.
I've put the whole stuff in a <vector> of MaterialDescriptor
classes, with every single object holding a ChunkMaterialPtr
pointing to the the appropriate material.
Here is the problem: i want to switch the materials on the fly,
via a fox simple interface. I have for now 4 simple materials.
When i engage the materials the first time, all goes good, so i can kick
in material 1, 2, 3, 4 and all are displayed correctly.
The problem starts when i put back on a material that
was already displayed.
For example if i switch on materials 1,3,4,3, when i put on the
3rd material again, my app crashes, every time.
I switch the materials with a simple:
for (int
materialNum=0;materialNum<m_MaterialDescriptor.size()&&trovato!=TRUE;materialNum++)
{
if(!strcmp(str.text(),m_MaterialDescriptor[materialNum]->GetMaterialName()))
{
osg::beginEditCP(group);
group->setMaterial(m_MaterialDescriptor[materialNum]->GetChunkMaterial());
osg::endEditCP(group);
if(m_MaterialDescriptor[materialNum]->GetChunkMaterial()==osg::NullFC)
printf ("No pointer\n");
if (group==osg::NullFC)
printf ("no group\n");
trovato=TRUE;
}
my first guess is that the material pointers go somehow lost in the
assign part, but as long as they are different from NullFC it should
work... Weird thing...
any ideas?
thanks for the help, enrico
-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now.
http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click
_______________________________________________
Opensg-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/opensg-users
-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now.
http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click
_______________________________________________
Opensg-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/opensg-users
-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now.
http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click
_______________________________________________
Opensg-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/opensg-users
-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now.
http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click
_______________________________________________
Opensg-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/opensg-users