Hi Andreas,

  The second one is bug

  4635636 - NullPointerException in Shape3DRetained.getMirrorShape when collision 
activate

  which is fixed in v1.3 beta2.

   Actually View.stopView() will also stop the BehaviorScheduler
so there is no need to explicitly stop it. I test the similar
setup using the attach program,

        view.stopView();
        view.stopBehaviorScheduler();
        System.out.println(view.isBehaviorSchedulerRunning());

under v1.2.1-v1.3beta2 and it run fine.

The only case it didn't work is viewPlatform not attach yet or not setLive
when stopBehaviorScheduler is invoked which bug 4687389 is filed
for this.

Thanks.

- Kelvin
--------------
Java 3D Team
Sun Microsystems Inc.

>Date: Fri, 17 May 2002 22:08:31 +0200
>From: Andreas Jerke <[EMAIL PROTECTED]>
>Subject: RE: [JAVA3D] Behaviour Scheduler does not stop
>To: 'Kelvin Chung' <[EMAIL PROTECTED]>
>MIME-version: 1.0
>X-MIMEOLE: Produced By Microsoft MimeOLE V6.00.2600.0000
>Content-transfer-encoding: 7bit
>Importance: Normal
>X-Priority: 3 (Normal)
>X-MSMail-priority: Normal
>
>::Hi Andreas,
>::
>::  Do you have a live viewPlatform attach to View when
>::v.stopBehaviorScheduler() is invoked ?
>yes, it's live but not running ( v.stopView() )
>
>::
>::  I can see from the current source code that there
>::is a bug causing isBehaviorSchedulerRunning()
>::always return true in this case.
>
>Ok, now my Thread does not wait for isBehaviorSchedulerRunning().
>But sometimes the JVM hangs again, or I get:
>
>java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
>        at java.util.ArrayList.RangeCheck(ArrayList.java:486)
>        at java.util.ArrayList.get(ArrayList.java:302)
>        at
>javax.media.j3d.Shape3DRetained.getMirrorShape(Shape3DRetained.java:2034
>)
>        at
>javax.media.j3d.WakeupOnCollisionEntry.addBehaviorCondition(WakeupOnColl
>isionEntry.java:290)
>        at
>javax.media.j3d.WakeupCriterion.buildTree(WakeupCriterion.java:64)
>        at
>javax.media.j3d.BehaviorStructure.activateBehaviors(BehaviorStructure.ja
>va:255)
>        at
>javax.media.j3d.BehaviorStructure.processMessages(BehaviorStructure.java
>:178)
>        at
>javax.media.j3d.StructureUpdateThread.doWork(StructureUpdateThread.java:
>83)
>        at javax.media.j3d.J3dThread.run(J3dThread.java:256)
>
>I will try to wait some time for the v.stopBehaviorScheduler() without
>asking isBehaviorSchedulerRunning() ...
>
>::
>::- Kelvin
>::------------------
>::Java 3D Team
>::Sun Microsystems Inc.
>::
>::
>::>Date: Fri, 17 May 2002 21:12:49 +0200
>::>From: Andreas Jerke <[EMAIL PROTECTED]>
>::>Subject: [JAVA3D] Behaviour Scheduler does not stop
>::>To: [EMAIL PROTECTED]
>::>MIME-version: 1.0
>::>X-MIMEOLE: Produced By Microsoft MimeOLE V6.00.2600.0000
>::>Content-transfer-encoding: 7bit
>::>Importance: Normal
>::>X-Priority: 3 (Normal)
>::>X-MSMail-priority: Normal
>::>Delivered-to: [EMAIL PROTECTED]
>::>
>::>Hello,
>::>
>::>I'm developing a SceneGraph inspector. This is a Swing Jtree which
>::>views the actual SceneGraph for debug and development.
>::>
>::>This JTree listens to a tree model called InspectorLocal (a Locale
>::>implementing interface TreeModel). So you can use InspectorLocale
>::>instead of Locale for debugging.
>::>
>::>To get access to all live Nodes and NodeComponets in
>::InspectorLocale, I
>::>have to detach all BranchGroups, perform all necessary access to the
>::>SceneGraph references and after this reattach all BranchGroups. I
>::>perform this detaching/reattach in a Thread, so the Jtree is
>::fast and
>::>has a smart usability without "hanging" . The Thread will wait some
>::>milliseconds before reattaching, because the JTree will call the
>::>methods implemented by TreeModel several times for every view update.
>::>
>::>This works fine for SceneGraphs without Behaviours. When using
>::>InspectorLocale on SceneGraphs with Behaviours, the application will
>::>hang. I assume this is because of the J3D Behavior Scheduler is not
>::>synchronized with my Thread. So I stop the Scheduler before
>::detaching
>::>Branchgroups. Here is the run() method in InspectorLocale:
>::>
>::>    public void run () {
>::>
>::>                [...]
>::>
>::>        //stop rendering and behaviour scheduler
>::>        View v = this.viewer.getView();
>::>        v.stopView();
>::>        long[] milis = v.stopBehaviorScheduler();
>::>
>::>        while (v.isBehaviorSchedulerRunning() || v.isViewRunning()) {
>::>                try {
>::>                    thread.sleep(this.THREAD_MAX_SLEEP);
>::>                    System.out.println("waiting for view to stop ...
>::>Scheduler:"+v.isBehaviorSchedulerRunning()+" begin:"+milis[0]+"
>::>end:"+milis[1]+" View running:"+v.isViewRunning());
>::>                } catch (InterruptedException e){
>::>                    System.out.println("interrupted while
>::waiting for
>::>view stop !");
>::>                }
>::>        }
>::>
>::>        Iterator iter = rootBG.iterator();
>::>        while (iter.hasNext()) {
>::>            try {
>::>                super.addBranchGraph((BranchGroup)iter.next());
>::>            } catch (CapabilityNotSetException e) {
>::>                System.out.println("Could not reattach
>::BranchGroup !");
>::>            }
>::>        }
>::>
>::>        v.startView();
>::>          v.startBehaviorScheduler();
>::>
>::>        detached = false;
>::>    }
>::>
>::>
>::>Now my problem:
>::>The method isBehaviorSchedulerRunning() ALLWAYS returns true, also I
>::>stopped the schedular process. My Thread hangs in a continuous loop.
>::>
>::>Anyone else having a similiar problem ?
>::>
>::>Cheers,
>::>Andreas
>::>
>::>=============================================================
>::==========
>::>====
>::>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".
>::
>::==============================================================
>::=============
>::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".
>::
>
/*
 *      %Z%%M% %I% %E% %U%
 *
 * Copyright (c) 1996-1999 Sun Microsystems, Inc. All Rights Reserved.
 *
 * Sun grants you ("Licensee") a non-exclusive, royalty free, license to use,
 * modify and redistribute this software in source and binary code form,
 * provided that i) this copyright notice and license appear on all copies of
 * the software; and ii) Licensee does not utilize the software in a manner
 * which is disparaging to Sun.
 *
 * This software is provided "AS IS," without a warranty of any kind. ALL
 * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY
 * IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
 * NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE
 * LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING
 * OR DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR ITS
 * LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT,
 * INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER
 * CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF
 * OR INABILITY TO USE SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGES.
 *
 * This software is not designed or intended for use in on-line control of
 * aircraft, air traffic, aircraft navigation or aircraft communications; or in
 * the design, construction, operation or maintenance of any nuclear
 * facility. Licensee represents and warrants that it will not use or
 * redistribute the Software for such purposes.
 */

import java.awt.*;
import java.awt.event.*;
import javax.media.j3d.*;
import javax.vecmath.*;
import com.sun.j3d.utils.geometry.ColorCube;
import com.sun.j3d.utils.universe.*;

class StartStopViewPanel extends Panel implements ActionListener {
    private StartStopView startStop;
    private Button stopButton;
    private Button startButton;
    private Button quitButton;

    public void actionPerformed (ActionEvent event) {
        Object target = event.getSource();

        if (target == stopButton) {
            startStop.stopInterpolators();
        }
        else if (target == startButton) {
            startStop.startInterpolators();
        }
        else if (target == quitButton) {
            System.exit(0);
        }
    }

    public void paint(Graphics g) {
        Dimension d = getSize();
        g.drawRect(0, 0, d.width - 1, d.height - 1);
    }

    public StartStopViewPanel(StartStopView startStop) {
        this.startStop = startStop;

        stopButton = new Button("Stop");
        startButton = new Button("Start");
        quitButton = new Button("Quit");

        stopButton.addActionListener(this);
        startButton.addActionListener(this);
        quitButton.addActionListener(this);

        setLayout(new FlowLayout());
        add(stopButton);
        add(startButton);
        add(quitButton);
    }
}

public class StartStopView extends Frame {

    View view = null;

    public BranchGroup createSceneGraph() {
        // Create the root of the branch graph
        BranchGroup objRoot = new BranchGroup();

        // Create a Transformgroup to scale all objects so they
        // appear in the scene.
        TransformGroup objScale = new TransformGroup();
        Transform3D t3d = new Transform3D();
        t3d.setScale(0.4);
        objScale.setTransform(t3d);
        objRoot.addChild(objScale);

        // Create the transform group node and initialize it to the
        // identity.  Enable the TRANSFORM_WRITE capability so that
        // our behavior code can modify it at runtime.  Add it to the
        // root of the subgraph.
        TransformGroup objTrans = new TransformGroup();
        objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
        objScale.addChild(objTrans);

        // Create a simple shape leaf node, add it to the scene graph.
        objTrans.addChild(new ColorCube());

        // Create a new Behavior object that will perform the desired
        // operation on the specified transform object and add it into
        // the scene graph.
        Transform3D yAxis = new Transform3D();
        Alpha rotationAlpha = new Alpha(-1, Alpha.INCREASING_ENABLE,
                                        0, 0,
                                        4000, 0, 0,
                                        0, 0, 0);

        RotationInterpolator rotator =
            new RotationInterpolator(rotationAlpha, objTrans, yAxis,
                                     0.0f, (float) Math.PI*2.0f);
        BoundingSphere bounds =
            new BoundingSphere(new Point3d(0.0,0.0,0.0), 100.0);
        rotator.setSchedulingBounds(bounds);
        objTrans.addChild(rotator);

        return objRoot;
    }

    public void stopInterpolators() {
        view.stopView();
        view.stopBehaviorScheduler();
        System.out.println(view.isBehaviorSchedulerRunning());

    }

    public void startInterpolators() {
        view.startView();
        view.startBehaviorScheduler();
    }

    public StartStopView() {
        Canvas3D c = new Canvas3D(SimpleUniverse.getPreferredConfiguration());

        // Handle the close event
        addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent winEvent) {
                System.exit(0);
            }
        });

        StartStopViewPanel startStopPanel
            = new StartStopViewPanel(this);
        startStopPanel.setSize(0, 100);
        add("North", startStopPanel);
        add("Center", c);
        setTitle("Java3D: View Start Stop Test");
        setSize(256, 256);
        setVisible(true);

        // Create a simple scene and attach it to the virtual universe
        BranchGroup scene = createSceneGraph();
        SimpleUniverse u = new SimpleUniverse(c);
        view = u.getViewer().getView();
        // This will move the ViewPlatform back a bit so the
        // objects in the scene can be viewed.
        u.getViewingPlatform().setNominalViewingTransform();

        u.addBranchGraph(scene);
    }

    public static void main(String[] args) {
        new StartStopView();
    }
}

Reply via email to