Ahh, that's the answer I was looking for.  I couldn't test it right
away because I was not at work.  But I just did and it works
perfectly.

thanks for your help all of you.

On Thu, Aug 28, 2008 at 7:45 AM, Vican, Justin E. <[EMAIL PROTECTED]> wrote:
> Hi Louis,
> When you pass the osg::Program* to the StateSet, the StateSet object holds
> on to it as an osg::ref_ptr<osg::Program>.  When you call removeAttribute,
> that ref_ptr de-references the program. Because you are keeping a pointer to
> the program and not a ref_ptr to the program, the reference count in the
> osg::Program class goes to zero, and the osg::Program object is deleted by
> the osg::ref_ptr class inside of the StateSet::removeAttribute method.
> Therefore, after you call removeAttribute, the pointer that you have is
> pointing to invalid memory ... the program has been deleted out from under
> you.  Use the osg::ref_ptr class, and the problem will be solved.  I had the
> exact same issue, and this solution resolved it.
> -Justin
> ________________________________
> From: [EMAIL PROTECTED] on behalf of Louis Bouchard
> Sent: Thu 8/28/2008 12:07 AM
> To: [EMAIL PROTECTED]; OpenSceneGraph Users
> Subject: Re: [osg-users] Fwd: Strange stateset / shader problem
>
> it's a osg::Program*.  The thing is, after the call to
> removeAttribute(), the osg::Program* is still valid.  The object has
> not been deleted, and the pointer is certainly not null.  I checked.
> Unless something inside the osg::Program structure has been screwed
> with.
>
> I don't see how ref_ptrs are necessary in that case.  I understand why
> they can be practical, like boost's shared_ptr, but hardly necessary
> all the time.  Their main use is to have objects automatically deleted
> when the ref count hit 0, so you don't have to destro them manually,
> right?
>
> Then, in my case, I certainly don't explicitely destroy the
> osg::program, and in the source code for StateSet, the pointer is
> removed form a std::vector<StateAttribute>, which I don't think
> implies the destruction of the object referred to by the pointer.
>
>
> On Wed, Aug 27, 2008 at 9:07 PM, Gordon Tomlinson
> <[EMAIL PROTECTED]> wrote:
>>
>> I would guess it is a reference count issue if you want to add and remove
>> and keep a reference counted object then you could call ::ref() on the
>> object when you create it or use the preferred method of using a variable
>> an
>> osg::ref_ptr<object> to preserve the scope of the object
>>
>> __________________________________________________________
>> Gordon Tomlinson
>>
>> [EMAIL PROTECTED]
>> IM: [EMAIL PROTECTED]
>> www.vis-sim.com www.gordontomlinson.com
>> __________________________________________________________
>>
>> -----Original Message-----
>> From: [EMAIL PROTECTED]
>> [mailto:[EMAIL PROTECTED] On Behalf Of Louis
>> Bouchard
>> Sent: Wednesday, August 27, 2008 5:52 PM
>> To: [email protected]
>> Subject: [osg-users] Fwd: Strange stateset / shader problem
>>
>> Hi,
>>
>> since we cannot turn off a shader program like this:
>>
>> setAttributeAndModes(shaderprogram, osg::StateAttribute::OFF)
>>
>> .. I tried the suggested method from this post
>> (http://www.mail-archive.com/[EMAIL PROTECTED]/msg08493.html),
>> and I simply removeAttribute(...) the shader from the stateset.  This
>> part works quite well.
>>
>> However, if I want to turn it back on again,
>> setAttributeAndModes(shaderprogram, osg::StateAttribute::ON) produces
>> a segmentation fault.  I have no idea why.  The shaderprogram pointer
>> is still valid.  I ran this through gdb and it was unhelpful.
>>
>> any ideas?
>>
>> thanks,
>>
>> Louis Bouchard
>> _______________________________________________
>> osg-users mailing list
>> [email protected]
>> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>>
>> _______________________________________________
>> osg-users mailing list
>> [email protected]
>> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>>
> _______________________________________________
> osg-users mailing list
> [email protected]
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>
> _______________________________________________
> osg-users mailing list
> [email protected]
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>
>
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to