I think I have uncovered a bug regarding Switch with a child SharedGroup.

Here is a test program. Setting boolean willCrash = true generates the
following Exception.

java.lang.NullPointerException
        at
javax.media.j3d.ContainsNodesList.getContainsNodes(ContainsNodesList.java:28
)
        at
javax.media.j3d.Shape3DRetained.setLive(Shape3DRetained.java:1092)
        at javax.media.j3d.GroupRetained.doSetLive(GroupRetained.java:1475)
        at javax.media.j3d.GroupRetained.setLive(GroupRetained.java:1209)
        at
javax.media.j3d.SharedGroupRetained.setLive(SharedGroupRetained.java:108)
        at javax.media.j3d.LinkRetained.setLive(LinkRetained.java:140)
        at javax.media.j3d.GroupRetained.doSetLive(GroupRetained.java:1475)
        at javax.media.j3d.SwitchRetained.setLive(SwitchRetained.java:370)
        at javax.media.j3d.GroupRetained.doSetLive(GroupRetained.java:1475)
        at
javax.media.j3d.TransformGroupRetained.setLive(TransformGroupRetained.java:3
22)
        at javax.media.j3d.GroupRetained.doSetLive(GroupRetained.java:1475)
        at
javax.media.j3d.BranchGroupRetained.setLive(BranchGroupRetained.java:101)
        at javax.media.j3d.Locale.doAddBranchGraph(Locale.java:183)
        at javax.media.j3d.Locale.addBranchGraph(Locale.java:159)
        at
com.sun.j3d.utils.universe.SimpleUniverse.addBranchGraph(SimpleUniverse.java
:235)
        at TestSwitch.<init>(TestSwitch.java:49)
        at TestSwitch.main(TestSwitch.java:62)

Raffi

/************************TestSwitch.java****************************/
import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
import com.sun.j3d.utils.applet.MainFrame;
import com.sun.j3d.utils.geometry.*;
import com.sun.j3d.utils.universe.*;
import javax.media.j3d.*;
import javax.vecmath.*;

public class TestSwitch extends Applet{

    boolean willCrash = true;
    Switch switchG;

    public BranchGroup createScene(){
        BranchGroup root = new BranchGroup();
        TransformGroup TG1 = new TransformGroup();
        TransformGroup TG2 = new TransformGroup();
        Transform3D T = new Transform3D();
        switchG = new Switch();
        switchG.setCapability( Switch.ALLOW_SWITCH_READ );
        switchG.setCapability( Switch.ALLOW_SWITCH_WRITE );
        SharedGroup cube = new SharedGroup();
        cube.addChild( new ColorCube(0.1) );

        T.set( new Vector3d( -0.5, 0, 0 ) );
        TG1.setTransform( T );
        TG1.addChild( new Link( cube ) );

        T.set( new Vector3d( 0.5, 0, 0 ) );
        TG2.setTransform( T );
        TG2.addChild( switchG );
        switchG.addChild( new Link( cube ) );

        if( willCrash ){
            root.addChild( TG1 );
            root.addChild( TG2 );
        }else{
            root.addChild( TG2 );
            root.addChild( TG1 );
        }
        return root;
    }
    public TestSwitch() {
        GraphicsConfiguration config =
SimpleUniverse.getPreferredConfiguration();
        Canvas3D canvas = new Canvas3D(config);
        SimpleUniverse universe = new SimpleUniverse(canvas);
        universe.getViewingPlatform().setNominalViewingTransform();
        universe.addBranchGraph( createScene() );

        setLayout(new BorderLayout());
        add("Center", canvas);
        Button switcher = new Button( "Switch" );
        switcher.addActionListener( new ActionListener(){
            public void actionPerformed( ActionEvent e ){
                switchShape();
            }
        });
        add( "South", switcher );
    }
    public static void main( String[] arg ){
        new MainFrame(new TestSwitch(), 256, 256);
    }
    public void switchShape(){
        int mask = switchG.getWhichChild() == Switch.CHILD_ALL ?
Switch.CHILD_NONE : Switch.CHILD_ALL;
        switchG.setWhichChild( mask );
    }
}

===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA3D-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".

Reply via email to