Hi Rahul,

   I've modify an example program to detach/attach a
custom behavior. However the bug can't be reproduced using
it. Can you please examine the test program and modify it
to simulate the action that your program perform so
that the bug appear ?

Thanks.

- Kelvin
------------
Java 3D Team
Sun Microsystems Inc.
   
>Delivered-To: [EMAIL PROTECTED]
>X-Originating-IP: [24.181.197.54]
>Mime-Version: 1.0
>X-OriginalArrivalTime: 10 Sep 2001 23:34:03.0872 (UTC) 
FILETIME=[139A3600:01C13A51]
>Date: Mon, 10 Sep 2001 23:34:03 +0000
>From: Rahul Choudhury <[EMAIL PROTECTED]>
>Subject: Re: [JAVA3D] processStimulus is not getting called..
>Comments: cc: [EMAIL PROTECTED]
>To: [EMAIL PROTECTED]
>
>Kelvin:
>
>Thanks for the prompt reply.
>
>>Which version of Java3D are you using ?
>We are using Java 3D 1.2.1_03 and the JavaTM 2 Platform, Standard Edition
>v1.3.1_01
>
>>What wakeup criteria are use in the custom behavior ?
>Here is a code snippet.
>
>****
>
>criterion = new WakeupCriterion[7];
>criterion[0] = new WakeupOnAWTEvent(MouseEvent.MOUSE_MOVED) ;
>criterion[1] = new WakeupOnAWTEvent(MouseEvent.MOUSE_PRESSED);
>criterion[2] = new WakeupOnAWTEvent(MouseEvent.MOUSE_DRAGGED);
>criterion[3] = new WakeupOnAWTEvent(MouseEvent.MOUSE_CLICKED);
>criterion[4] = new WakeupOnAWTEvent(MouseEvent.MOUSE_RELEASED);
>criterion[5] = new WakeupOnAWTEvent(KeyEvent.KEY_RELEASED);
>criterion[6] = new WakeupOnAWTEvent(KeyEvent.KEY_PRESSED);
>wakeupOn( new WakeupOr( criterion ));
>
>>Can you check to see if the custom behavior public void initialize()
>>method is being invoked every time the behavior branch
>>is detach and attach again ?
>
>Yes, I did check that. And the public void initialize method is getting
>called every time a new VRML world is loaded.
>
>>When window minmize and maximize again, there is
>>some wakeup conditions flag in behavior being reset.
>>You can achieve the same effect by using start/stop
>>View.
>
>After the new VRML world is loaded, I tried couple of things (as I mentioned
>earlier). Here is some code snippet
>
>Canvas3D canvas3D = vrmlDisplayer.getCanvas3D();
>View view = canvas3D.getView();
>view.stopView();
>view.startView();
>view.stopBehaviorScheduler();
>view.startBehaviorScheduler();
>canvas3D.stopRenderer();
>canvas3D.startRenderer();
>
>But even then the processStimulus method is not getting called. The only
>time it does get called when I manually minimize and maximize the window.
>Let me know if you can help in any ways.
>
>Thanks,
>Rahul
>
>
>>
>>
>> >Delivered-To: [EMAIL PROTECTED]
>> >X-Originating-IP: [24.181.197.54]
>> >Mime-Version: 1.0
>> >X-OriginalArrivalTime: 10 Sep 2001 19:25:21.0313 (UTC)
>>FILETIME=[55106910:01C13A2E]
>> >Date: Mon, 10 Sep 2001 19:25:21 +0000
>> >From: Rahul Choudhury <[EMAIL PROTECTED]>
>> >Subject: [JAVA3D] processStimulus is not getting called..
>> >To: [EMAIL PROTECTED]
>> >
>> >Hi all:
>> >
>> >I am using Java3D in an application used for 3D training. The application
>> >uses VRML worlds for its 3D data. We have a VRML loader/browser which
>>loads
>> >and manipulates the world. The application has 3 modes. In each mode a
>> >separate VRML world is loaded (after unloading the old VRML world). So at
>>a
>> >time there is only one VRML world loaded.
>> >
>> >Every time a vrml world is loaded, we attach a customized Behavior node
>> >(CustomBehavior) to the world, which helps users to navigate around.
>>Other
>> >than navigation, it also assists in notifying when user touches a
>> >TouchSensor or performs other activities.
>> >
>> >The problem that I have happens only when an old VRML world is unloaded
>>and
>> >the new one is loaded
>> >
>> >Lets say the User changed mode from Mode A to Mode B
>> >
>> >1. The application unloads the VRML World 1 related to Mode A. We make
>>sure
>> >that the world is properly unloaded. We called
>> >VirtualUniverse.removeAllLocales and made sure all other references
>>related
>> >to the World 1 are gone. I run the application using OptimizeIt and found
>> >that in deed all necessary memory was freed up and unloading was
>>happening
>> >properly. So no problem so far.
>> >
>> >2. The world then loads up VRML World 2 related to mode B. I can see the
>> >world. However I can not move around or click on any TouchSensor.
>> >
>> >After further investigation, I found out the reason. I saw that the class
>> >CustomBehvaior which is responsible for navigation etc, is not receiving
>>and
>> >processStimulus method from Java3D scheduler. As a result, nothing was
>> >happening.
>> >
>> >I also noticed that when I manually minimize (iconify) the application's
>> >JFrame (by clicking on Frame's minimize icon) and maximize it again,
>> >everything becomes OK. In other words, the processStimulus method of the
>> >CustomBehavior class starts getting call from Java 3D scheduler as and
>>when
>> >user presses / drags mouse on the Canvas3D.
>> >
>> >I would like to know if there is any solution to this problem. I tried
>> >stopping and starting the renderer after the second world is loaded. That
>> >didn�t work. I invalidated and validated the parent Frame (as well as
>> >Canvas3D) after the second world is loaded. That didnt work too. I tried
>> >repainting everything, that didn't work as well.
>> >
>> >I am wondering what happens in the Java3D renderer when I manually
>>minimize
>> >and maximize the parent Frame. Because whatever it is, that apparently
>>fixes
>> >my problem.
>> >
>> >_________________________________________________________________
>> >Get your FREE download of MSN Explorer at
>>http://explorer.msn.com/intl.asp
>> >
>> >===========================================================================
>> >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".
>>
>
>
>_________________________________________________________________
>Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp
>
>===========================================================================
>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-2001 Sun Microsystems, Inc. All Rights Reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 * - Redistributions of source code must retain the above copyright
 *   notice, this list of conditions and the following disclaimer.
 *
 * - Redistribution in binary form must reproduce the above copyright
 *   notice, this list of conditions and the following disclaimer in
 *   the documentation and/or other materials provided with the
 *   distribution.
 *
 * Neither the name of Sun Microsystems, Inc. or the names of
 * contributors may be used to endorse or promote products derived
 * from this software without specific prior written permission.
 *
 * 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.
 *
 * You acknowledge that Software is not designed,licensed or intended
 * for use in the design, construction, operation or maintenance of
 * any nuclear facility.
 */

import java.applet.Applet;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.awt.event.WindowAdapter;
import com.sun.j3d.utils.applet.MainFrame;
import com.sun.j3d.utils.geometry.ColorCube;
import com.sun.j3d.utils.universe.*;
import javax.media.j3d.*;
import javax.vecmath.*;

public class AWTInteraction extends Applet implements ActionListener {
    TransformGroup objTrans;
    BranchGroup detachBranch;
    boolean added = true;

    JButton actionB = new JButton("Attach/Detach");

    private SimpleUniverse u = null;

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

        // 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.
        objTrans = new TransformGroup();
        objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
        objRoot.addChild(objTrans);

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

        AWTInteractionBehavior awtBehavior =
            new AWTInteractionBehavior();
        actionB.addActionListener(this);

        BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0),
                                                   100.0);
        awtBehavior.setSchedulingBounds(bounds);

        detachBranch = new BranchGroup();
        detachBranch.setCapability(BranchGroup.ALLOW_DETACH);
        detachBranch.addChild(awtBehavior);
        detachBranch.addChild(new ColorCube(0.4));
        objTrans.addChild(detachBranch);
        objTrans.setCapability(Group.ALLOW_CHILDREN_WRITE);
        objTrans.setCapability(Group.ALLOW_CHILDREN_EXTEND);
        return objRoot;
    }

    public void actionPerformed(ActionEvent e) {
        if (added) {
            System.out.println("detach");
            detachBranch.detach();
            added = false;
        }  else {
            System.out.println("attach");
            objTrans.addChild(detachBranch);
            added = true;
        }
    }

    public AWTInteraction() {
    }

    public void init() {
        setLayout(new BorderLayout());
        GraphicsConfiguration config =
           SimpleUniverse.getPreferredConfiguration();

        Canvas3D c = new Canvas3D(config);
        add("Center", c);

        JPanel p = new JPanel();
        p.add(actionB);
        add("North", p);

        // Create a simple scene and attach it to the virtual universe
        BranchGroup scene = createSceneGraph();
        scene.setCapability( BranchGroup.ALLOW_BOUNDS_READ );
        u = new SimpleUniverse(c);

        // This will move the ViewPlatform back a bit so the
        // objects in the scene can be viewed.
        u.getViewingPlatform().setNominalViewingTransform();

        u.addBranchGraph(scene);

    }

    public void destroy() {
        u.removeAllLocales();
    }

    //
    // The following allows HelloUniverse to be run as an application
    // as well as an applet
    //
    public static void main(String[] args) {
        new MainFrame(new AWTInteraction(), 256, 256);
    }
}
/*
 *      %Z%%M% %I% %E% %U%
 *
 * Copyright (c) 1996-2001 Sun Microsystems, Inc. All Rights Reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 * - Redistributions of source code must retain the above copyright
 *   notice, this list of conditions and the following disclaimer.
 *
 * - Redistribution in binary form must reproduce the above copyright
 *   notice, this list of conditions and the following disclaimer in
 *   the documentation and/or other materials provided with the
 *   distribution.
 *
 * Neither the name of Sun Microsystems, Inc. or the names of
 * contributors may be used to endorse or promote products derived
 * from this software without specific prior written permission.
 *
 * 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.
 *
 * You acknowledge that Software is not designed,licensed or intended
 * for use in the design, construction, operation or maintenance of
 * any nuclear facility.
 */

import java.awt.*;
import java.awt.event.*;
import javax.media.j3d.*;
import javax.vecmath.*;
import java.util.*;

public class AWTInteractionBehavior extends Behavior {


    private WakeupOr wakeupCond;


    // create a new AWTInteractionBehavior
    public AWTInteractionBehavior() {
    }

    // initialize the behavior to wakeup on a behavior post with the id
    // MouseEvent.MOUSE_CLICKED
    public void initialize() {
        WakeupCriterion criterion[] = new WakeupCriterion[7];
        criterion[0] = new WakeupOnAWTEvent(MouseEvent.MOUSE_MOVED) ;
        criterion[1] = new WakeupOnAWTEvent(MouseEvent.MOUSE_PRESSED);
        criterion[2] = new WakeupOnAWTEvent(MouseEvent.MOUSE_DRAGGED);
        criterion[3] = new WakeupOnAWTEvent(MouseEvent.MOUSE_CLICKED);
        criterion[4] = new WakeupOnAWTEvent(MouseEvent.MOUSE_RELEASED);
        criterion[5] = new WakeupOnAWTEvent(KeyEvent.KEY_RELEASED);
        criterion[6] = new WakeupOnAWTEvent(KeyEvent.KEY_PRESSED);
        wakeupCond = new WakeupOr( criterion );
        wakeupOn(wakeupCond);
    }

    // processStimulus to rotate the cube
    public void processStimulus(Enumeration criteria) {
        WakeupOnAWTEvent evt = (WakeupOnAWTEvent)
                                 criteria.nextElement();
        System.out.println(evt.getAWTEvent()[0]);
        wakeupOn(wakeupCond);
    }

}

Reply via email to