Hello Gerrit,

sorry for the delay!

Unfortunately, I can not reproduce this erro after I have changed my code 
according to

http://www.mail-archive.com/opensg-users%40lists.sourceforge.net/msg14302.html .

The hanging has vanished.

What I have changed you can find below. Avoiding the deepClone does seem to 
solve the problem. My intent here is to create a highlight material that has 
some default properties but that does must take the transparency of the 
switch 0 material. Is there a better way to solve that task?

Should I send the requested data anyhow?

Best,
Johannes



class set_highlight_helper
{
public:
    set_highlight_helper(ChunkMaterial* mat) : _highlightMaterial(mat) {}

    Action::ResultE enter(Node* node)
    {
        using namespace osg;
        Material* mat = NULL;
        NodeCore* core = node->getCore();

        MaterialGroup* mgrp = dynamic_cast<MaterialGroup*>(core);
        if (mgrp) {
            mat = mgrp->getMaterial();
        } else {
            MaterialChunkOverrideGroup* mcogrp = 
dynamic_cast<MaterialChunkOverrideGroup*>(core);
            if (mcogrp)
                mat = mcogrp->getMaterial();
        }

        if (mat)
        {
            SwitchMaterial* switchMaterial = 
dynamic_cast<SwitchMaterial*>(mat);
            if (switchMaterial) {
                if (!_highlightMaterial) {
                    switchMaterial->setChoice(0);
                    if (switchMaterial->editMFMaterials()->size() > 1) {
                        
switchMaterial->subMaterial(switchMaterial->getMaterial(1));
                    }
                } else {
                    //ChunkMaterialUnrecPtr matHL = 
dynamic_pointer_cast<ChunkMaterial>(deepClone(_highlightMaterial)); 
// no deepClone anymore
                    ChunkMaterialUnrecPtr matHL = 
dynamic_pointer_cast<ChunkMaterial>(replicateChunkMatrial(_highlightMaterial));
                    if (matHL)
                    {
                        ChunkMaterial* matOrg = 
dynamic_cast<ChunkMaterial*>(switchMaterial->getMaterial(0));

                        transferTransparency(matOrg, matHL);

                        if (switchMaterial->editMFMaterials()->size() < 2)
                            switchMaterial->addMaterial(matHL);
                        else
                            (*(switchMaterial->editMFMaterials()))[1] = 
matHL;

                        switchMaterial->setChoice(1);
                    }
                }
            }
            return Action::Skip;
        }
        return Action::Continue;
    }

private:
    ChunkMaterial* _highlightMaterial;
};

osg::ChunkMaterialTransitPtr replicateChunkMatrial(const osg::ChunkMaterial* 
mat)
{
    using namespace osg;

    if (mat) {
        ChunkMaterialUnrecPtr new_mat = 
dynamic_pointer_cast<ChunkMaterial>(deepClone(mat));

        StateChunk* curr;

        curr = new_mat->find(ClipPlaneChunk::getClassType());
        while (curr) {
            new_mat->subChunk(curr);
            curr = new_mat->find(ClipPlaneChunk::getClassType());
        }

        curr = new_mat->find(LightModelChunk::getClassType());
        new_mat->subChunk(curr);

        curr = new_mat->find(ShaderProgramChunk::getClassType());
        while (curr) {
            new_mat->subChunk(curr);
            curr = new_mat->find(ShaderProgramChunk::getClassType());
        }

        const MFUnrecStateChunkPtr* chunks = mat->getMFChunks();
        MFUnrecStateChunkPtr::const_iterator iter = chunks->begin();
        MFUnrecStateChunkPtr::const_iterator end  = chunks->end();
        for (; iter != end; ++iter)
        {
            StateChunkUnrecPtr chunk = *iter;
            if (!chunk)
                continue;

            //
            // Transfer the scene manager managed chunks...
            //
            if( chunk->getTypeId() == ClipPlaneChunk::getClassTypeId()
             || chunk->getTypeId() == LightModelChunk::getClassTypeId()
             || chunk->getTypeId() == ShaderProgramChunk::getClassTypeId() )
            {
                new_mat->addChunk(chunk);
            }
        }

        return ChunkMaterialTransitPtr(new_mat);
    }

    return ChunkMaterialTransitPtr(NULL);
}





------------------------------------------------------------------------------
Keep Your Developer Skills Current with LearnDevNow!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-d2d
_______________________________________________
Opensg-users mailing list
Opensg-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/opensg-users

Reply via email to