From: Yair Kurzion (yair++at++polygon.engr.sgi.com)
Date: 08/27/2001 19:40:29
Hello Larry !
> I'm unsure if this is going to leak or not.....
>
>
> pfTexGen* texGen = new pfTexGen;
> assert(texGen);
> gState->setMode(PFSTATE_ENTEXGEN,PF_ON);
> gState->setAttr(PFSTATE_TEXGEN,texGen);
This will leak any previous TexGen on this gstate.
All pfGeoState::setAttr does is unref the existing TEXGEN attribute. It doesn't
delete it.
> What if the gState already HAD a pfTexGen? I know pfTexGen is a pfMemory object so
> it has reference counting, but is smart enough to know it is no longer needed, or do
> I have to give it kick in the head with unRef();
>
> And just for curiosity what would happen if I used
>
> ptr = gState->getAttr(PFSTATE_TEXGEN);
> pfDelete(ptr);
>
> the pfTexGen is STILL referenced by the gState.
This won't delete the texgen because its refcount is nonzero. Your gstate
still has a ref on the texgen.
> I've read the man page and I'm starting to think I should get the old pfTexGen, put
> the new one in, then pfCheckDelete() on the old one.
>
> If that is the correct solution, what happens when I call
>
> ptr = gState->getAttr(PFSTATE_TEXGEN);
>
> on a GeoState that never had a pfTexGen applied to it? Do I get a NULL pointer?
Yes. Attributes are initially NULL.
I would use:
pfTexGen* texGen = new pfTexGen;
pfTexGen* old_texGen = gState->getAttr(PFSTATE_TEXGEN);
gState->setMode(PFSTATE_ENTEXGEN,PF_ON);
gState->setAttr(PFSTATE_TEXGEN,texGen);
pfMemory::checkDelete (old_texGen);
// pfDelete does nothing on a NULL pointer.
-yair
--
\_________ \_____ \__ \__ \_____ Yair Kurzion
\_________ \_____ \__ \__ \_____ yair++at++sgi.com
\__ \__ \____\__ \__ http://reality.sgi.com/yair
\__ \__ \__ Work: (650) 933-6502
\__ \__ \__ Home: (408) 226-9771
\__ \__ \__
This archive was generated by hypermail 2b29 : Mon Aug 27 2001 - 19:40:39 PDT