Hi Eric,

The OSG automatically reference counts objects, so when you do the
setTexture..(0, txt2) the tx1 will be unref'd automatically and if no
other references exist it'll delete - which is correct.  Your tx1
pointer is now a dangling pointer and when you assign to the stateset
it of course crashes.

The simple solution is the use ref_ptr<osg::Texture> instead of the C
pointer.

Robert.

On Mon, Aug 24, 2009 at 2:23 PM, Eric
Pouliquen<[email protected]> wrote:
> Hi all,
>
> I'm trying to swap textures on a node, based on event for exemple.
> But let's see this simple code :
>
>
> Code:
> osg::Texture* tx1 = setTexture("test1.jpg");
> osg::Texture* tx2 = setTexture("test2.jpg");
>
> osg::Geode* sphereGeode = new osg::Geode;
> osg::StateSet* state1 = sphereGeode1->getOrCreateStateSet();
>
> state1->setTextureAttributeAndModes(0, tx1 );
> state1->setTextureAttributeAndModes(0, tx2 );
> state1->setTextureAttributeAndModes(0, tx1 );
>
>
>
> This code crashes because modifying the content of tx1 when setting the tx2 
> texture, so when re-applying tx1 in the third line, the tx1 pointer is 
> corrupted!
>
> So what is the way to manage multiple textures on the same node ?
> I don't want to use multiple textures indexes because I will probably swap on 
> many and many textures...
>
> Need I create a new StateSet per texture ?
>
> Thanks
>
> ------------------
> Read this topic online here:
> http://forum.openscenegraph.org/viewtopic.php?p=16635#16635
>
>
>
>
>
> _______________________________________________
> 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