JDK-7028648 : Java 3D does not display with Java 1.7
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 7
  • Priority: P2
  • Status: Closed
  • Resolution: Duplicate
  • OS: solaris_10
  • CPU: x86
  • Submitted: 2011-03-17
  • Updated: 2017-05-16
  • Resolved: 2011-05-10
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 7
7Resolved
Related Reports
Duplicate :  
Relates :  
Description
FULL PRODUCT VERSION :
java version "1.7.0-ea"
Java(TM) SE Runtime Environment (build 1.7.0-ea-b130)
Java HotSpot(TM) Server VM (build 21.0-b02, mixed mode)


ADDITIONAL OS VERSION INFORMATION :
SunOS ncssparc 5.10 Generic_144489-09 i86pc i386 i86pc

EXTRA RELEVANT SYSTEM CONFIGURATION :
Java 3D 1.5.2

A DESCRIPTION OF THE PROBLEM :
Java 3D objects do not display in a window with JDK 1.7.

REGRESSION.  Last worked in version 6u24

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Compile example and then run it.
../jdk1.7.0/bin/javac -cp ../j3d-1_5_2-solaris-x86/lib/ext/j3dcore.jar:../j3d-1_5_2-solaris-x86/lib/ext/j3dutils.jar:../j3d-1_5_2-solaris-x86/lib/ext/vecmath.jar HelloUniverse1.java
../jdk1.7.0/bin/java -cp ../j3d-1_5_2-solaris-x86/lib/ext/j3dcore.jar:../j3d-1_5_2-solaris-x86/lib/ext/j3dutils.jar:../j3d-1_5_2-solaris-x86/lib/ext/vecmath.jar HelloUniverse1

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
A window with a rotating cube.
ACTUAL -
A blank window.

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
/*
 * @(#)HelloUniverse1.java 1.55 02/10/21 13:43:36
 *
 * Copyright (c) 1996-2002 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.BorderLayout;
import java.awt.GraphicsConfiguration;

import javax.media.j3d.Alpha;
import javax.media.j3d.BoundingSphere;
import javax.media.j3d.BranchGroup;
import javax.media.j3d.Canvas3D;
import javax.media.j3d.RotationInterpolator;
import javax.media.j3d.Transform3D;
import javax.media.j3d.TransformGroup;
import javax.vecmath.Point3d;

import com.sun.j3d.utils.applet.MainFrame;
import com.sun.j3d.utils.geometry.ColorCube;
import com.sun.j3d.utils.universe.SimpleUniverse;


public class HelloUniverse1 extends Applet {

  private SimpleUniverse u = null;

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

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

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

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

    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);
    objRoot.addChild(rotator);

    // Have Java 3D perform optimizations on this scene graph.
    objRoot.compile();

    return objRoot;
  }

  public HelloUniverse1() {
  }

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

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

    // Create a simple scene and attach it to the virtual universe
    BranchGroup scene = createSceneGraph();
    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.cleanup();
  }

  //
  // The following allows HelloUniverse to be run as an application
  // as well as an applet
  //
  public static void main(String[] args) {
    new MainFrame(new HelloUniverse1(), 256, 256);
  }
}

---------- END SOURCE ----------

Comments
EVALUATION This CR is marked as a duplicate of 7041387 because 7041387 resolves the issue with Java3D applets. However, the changes initially proposed for 7028648 have not been integrated into JDK7 because 7041387 has resolved the issues the other way.
03-06-2011

EVALUATION The default behavior of the invalidate() method will be resotred with a fix for 7041387. After that the issue will disappear. So, I'm closing this bug as a duplicate of 7041387.
10-05-2011

SUGGESTED FIX --- old/src/share/classes/java/applet/Applet.java 2011-04-29 16:48:36.000000000 +0400 +++ new/src/share/classes/java/applet/Applet.java 2011-04-29 16:48:35.000000000 +0400 @@ -230,21 +230,6 @@ } /** - * Indicates if this container is a validate root. - * <p> - * {@code Applet} objects are the validate roots, and, therefore, they - * override this method to return {@code true}. - * - * @return {@code true} - * @since 1.7 - * @see java.awt.Container#isValidateRoot - */ - @Override - public boolean isValidateRoot() { - return true; - } - - /** * Requests that the argument string be displayed in the * "status window". Many browsers and applet viewers * provide such a window, where the application can inform users of --- old/src/share/classes/java/awt/Component.java 2011-04-29 16:48:37.000000000 +0400 +++ new/src/share/classes/java/awt/Component.java 2011-04-29 16:48:36.000000000 +0400 @@ -2851,8 +2851,34 @@ public void layout() { } + /* + * Returns the top-most invalid container of the component, or the nearest + * validate root (whichever comes first). The return value is {@code null} + * if the component is not placed in a container, or if its container is + * valid. Otherwise, this method returns a non-valid top-most container of + * the component. + */ + Container getInvalidRoot() { + checkTreeLock(); + + Container c = getContainer(); + + if (c == null || c.isValid()) { + return null; + } + + while (!c.isValidateRoot() && c.getContainer() != null) { + c = c.getContainer(); + } + + return c; + } + /** - * Validates this component. + * Validates the invalid component hierarchy that contains this component. + * <p> + * This method validates the topmost invalid container of this component, + * or the nearest validate root of the component, whichever comes first. * <p> * The meaning of the term <i>validating</i> is defined by the ancestors of * this class. See {@link Container#validate} for more details. @@ -2865,22 +2891,39 @@ */ public void validate() { synchronized (getTreeLock()) { - ComponentPeer peer = this.peer; - boolean wasValid = isValid(); - if (!wasValid && peer != null) { - Font newfont = getFont(); - Font oldfont = peerFont; - if (newfont != oldfont && (oldfont == null - || !oldfont.equals(newfont))) { - peer.setFont(newfont); - peerFont = newfont; - } - peer.layout(); - } - valid = true; - if (!wasValid) { - mixOnValidating(); + if (isValid()) { + return; } + + // Fixed 7028648 + Container root = getInvalidRoot(); + if (root != null) { + // Container overrides validate(), so there's no recursion + root.validate(); + } else { + validateImpl(); + } + } + } + + final void validateImpl() { + checkTreeLock(); + + ComponentPeer peer = this.peer; + boolean wasValid = isValid(); + if (!wasValid && peer != null) { + Font newfont = getFont(); + Font oldfont = peerFont; + if (newfont != oldfont && (oldfont == null + || !oldfont.equals(newfont))) { + peer.setFont(newfont); + peerFont = newfont; + } + peer.layout(); + } + valid = true; + if (!wasValid) { + mixOnValidating(); } } --- old/src/share/classes/java/awt/Container.java 2011-04-29 16:48:38.000000000 +0400 +++ new/src/share/classes/java/awt/Container.java 2011-04-29 16:48:38.000000000 +0400 @@ -1563,18 +1563,27 @@ super.invalidate(); } + @Override + final Container getInvalidRoot() { + if (isValidateRoot()) { + // no matter valid or not + return this; + } + return super.getInvalidRoot(); + } + /** - * Validates this container and all of its subcomponents. + * Validates the invalid component hierarchy that contains this container. + * <p> + * This method starts validation from the topmost invalid ancestor of this + * container, or the nearest validate root of the container, whichever + * comes first. If this container is a validate root, then validation + * starts from this container itself. * <p> * Validating a container means laying out its subcomponents. * Layout-related changes, such as setting the bounds of a component, or * adding a component to the container, invalidate the container - * automatically. Note that the ancestors of the container may be - * invalidated also (see {@link Component#invalidate} for details.) - * Therefore, to restore the validity of the hierarchy, the {@code - * validate()} method should be invoked on a validate root of an - * invalidated component, or on the top-most container if the hierarchy - * does not contain validate roots. + * automatically. * <p> * Validating the container may be a quite time-consuming operation. For * performance reasons a developer may postpone the validation of the @@ -1594,25 +1603,14 @@ public void validate() { boolean updateCur = false; synchronized (getTreeLock()) { - if ((!isValid() || descendUnconditionallyWhenValidating) - && peer != null) - { - ContainerPeer p = null; - if (peer instanceof ContainerPeer) { - p = (ContainerPeer) peer; - } - if (p != null) { - p.beginValidate(); - } - validateTree(); - if (p != null) { - p.endValidate(); - // Avoid updating cursor if this is an internal call. - // See validateUnconditionally() for details. - if (!descendUnconditionallyWhenValidating) { - updateCur = isVisible(); - } + if (!isValid() || descendUnconditionallyWhenValidating) { + // Fixed 7028648 + Container root = getInvalidRoot(); + if (root == null) { + root = this; } + + updateCur = root.validateTreeWrapper(); } } if (updateCur) { @@ -1620,6 +1618,34 @@ } } + /* + * Returns whether we should updateCursorImmediately(). + */ + private boolean validateTreeWrapper() { + if (peer == null) { + return false; + } + + ContainerPeer p = null; + if (peer instanceof ContainerPeer) { + p = (ContainerPeer) peer; + } + if (p != null) { + p.beginValidate(); + } + validateTree(); + if (p != null) { + p.endValidate(); + // Avoid updating cursor if this is an internal call. + // See validateUnconditionally() for details. + if (!descendUnconditionallyWhenValidating) { + return isVisible(); + } + } + + return false; + } + /** * Indicates whether valid containers should also traverse their * children and call the validateTree() method on them. @@ -1673,21 +1699,20 @@ } for (int i = 0; i < component.size(); i++) { Component comp = component.get(i); - if ( (comp instanceof Container) - && !(comp instanceof Window) - && (!comp.isValid() || - descendUnconditionallyWhenValidating)) - { - ((Container)comp).validateTree(); - } else { - comp.validate(); + if (!comp.isValid() || descendUnconditionallyWhenValidating) { + if (comp instanceof Container) { + ((Container)comp).validateTree(); + } else { + comp.validateImpl(); + } } } if (peer instanceof ContainerPeer) { ((ContainerPeer)peer).endLayout(); } } - super.validate(); + + validateImpl(); } /**
29-04-2011

EVALUATION The reason the Applet class has become a validate root is because usually applet developers do not have direct access to the parent of the applet (e.g. an embedded frame). Technically they could, of course, call the getParent() method, but such practice has never been known as common. Therefore, we thought that most probably applet developers would call validate() on the applet itself to validate the component hierarchy. And since the hw/lw mixing feature requires the whole component hierarchy to be valid, we had to make the applet a valdiate root to avoid invalidation of the embedded frame. To workround the issue described in this CR we'll do the following: 1. Revert the changes to the Applet so that it isn't a validate root anymore. This means that invalidation of anything down the applet's component hierarchy will also invalidate the frame. 2. The Component.validate() method will not validate this component (and its hierarchy if this is a container) directly, but instead will search upwards the component hierarchy to locate the nearset validate root (or the topmost container of the hierarchy, whichever comes first), and will validate the whole component hierarchy from there. We anticipate some performance regression for applications that call the validate() method on containers that aren't validate roots (that shouldn't be quite common though), but that seems to be the only reasonable way to fix the regression.
25-04-2011

EVALUATION This is a change of JDK behaviour that broke compatibility. We need to fix it in JDK. Java 3D isn't going to change.
22-04-2011

EVALUATION The applet's lifecycle implies that the Applet.init() method is called before showing the toplevel container of the applet (e.g. a plugin's embedded frame). Showing a top-level container validates the components unconditionally ignoring any validate roots, and therefore ensures that all components are validated (and thus correctly layouted) prior to presenting the applet on the screen. If we take a look at the com.sun.j3d.utils.applet.MainFrame class, we may notice that the sequence of operations is as follows (I've stripeed out non-essential calls): frame.add(applet); frame.setVisible(true); applet.init(); frame.validate(); // oops. there's a problem applet.start(); frame.validate(); // not necessary. In start() applet is responsible for validation Before the fix for 6852592 this indeed worked out well because when applet changed the layout related information in the init() method (e.g. added components), the invalidate() method invalidated the whole component hierarchy up to the top-level container. Therefore, a subsequent call to validate() managed to get to all the invalid components and relayouted them correctly. However, since 6852592 is fixed this is no longer supposed to work this way. The Applet class (amongst a number of other containers) are now validate roots, meaning that their internal lyaout doesn't effect the outer layout, which means that after invalidateing the applet panel itself, the invalidate() methods stops, and doesn't invalidate the upper container (the frame in our case). Therefore, the frame stays valid, and as such calling validate() on it is effectively a no-op. Generally, code that changes layout-related information is responsible for validating the hierarchy afterwards by means of calling the validate() method on the nearest validate root (*not* simply the top-most container of the hierarchy). Please refer to 6852592 and 6868255 for more information on the changes and clarifications to the specification. Swing applications enusre this contract by using the JCompoennt.revalidate() method after changing any layout-related information. Applets are allowed to perform initialization in the init() method and not care about validating the hierarchy because the Plugin shows the emebdded frame after calling the init() method, and the Window.show() always validates all components unconditionally (i.e. it doesn't stop on the valid frame, and goes deeper in the hierarchy instead). The MainFrame Java2D utility class obviously violates this rule, which leads to the applet being invalid, and as a result we don't see anything on the screen. I see two ways to fix this: 1. Move the frame.setVisible() call after the applet.init() call. This way the MainFrame will beasically simulate what the Plugin does. 2. Workaround the issue by calling sun.awt.AWTAccessor.getContainerAccessor().validateUnconditionally(frame) instead of plain validate() call after calling the applet.init() method.
22-04-2011

EVALUATION Is not a J2D issue. Its an AWT issue concerning component validation. The provided program fails as described on Windows 7 as well as Solaris from JDK 7 b77 onwards. The specific fix that caused it appears to be 6852592: invalidate() must be smarter which was discussed on this thread. http://mail.openjdk.java.net/pipermail/awt-dev/2009-September/000934.html One part of that fix is to add a new method public API method Container.isValidateRoot() and override it on java.applet.Applet to return true : http://cr.openjdk.java.net/~anthony/7-23-invalidate-6852592.3/src/share/classes/java/applet/Applet.java.sdiff.html The test program provided here is an Applet, run as a main program. If in that sample program I over-ride again as thus : public boolean isValidateRoot() { return false; } Then the program paints properly.
21-04-2011

EVALUATION Looks like a J2D issue.
05-04-2011