Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8179946

Objects are not rendered for certain rotation angle and cache hint combinations

XMLWordPrintable

    • generic
    • generic

      FULL PRODUCT VERSION :
      java version "1.8.0_152-ea"
      Java(TM) SE Runtime Environment (build 1.8.0_152-ea-b02)
      Java HotSpot(TM) 64-Bit Server VM (build 25.152-b02, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      OSX 10.10.5 MacBook Pro Retina NVIDIA GeForce GT 650M 1024 MB

      A DESCRIPTION OF THE PROBLEM :
      The test program draws several little windsock symbols at various angles.
      For the combination of a cache hint SPEED and a rotation angle of either 90°
      or 270° the symbol is just not drawn. This does not happen for any
      other cache hint setting.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Run the attached test program. There should be 10 symbols shown. If you have selected the cache hint SPEED only 8 symbols are shown.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      There should always be 10 symbols independently of the chosen cache hint.
      ACTUAL -
      If you have selected the cache hint SPEED only 8 symbols are shown.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      package bugs.cache;

      import javafx.application.Application;
      import javafx.geometry.Point2D;
      import javafx.scene.CacheHint;
      import javafx.scene.Group;
      import javafx.scene.Scene;
      import javafx.scene.layout.BorderPane;
      import javafx.scene.layout.Pane;
      import javafx.scene.layout.StackPane;
      import javafx.stage.Stage;

      /**
       * This demo shows a critical rendering problem of JavaFX.
       * The program draws several little windsock symbols at various angles.
       * For the combination of a cache hint SPEED and an angle of either 90°
       * or 270° the symbol is just not drawn. This does not happen for any
       * other cache hint setting.
       *
       * @author Michael Paus
       */
      public class CacheRenderingTest extends Application {

      // Error for CacheHint.SPEED. All other cache hint values seem to be ok.
      private final static CacheHint cacheHint = CacheHint.SPEED;

      private final static boolean cache = true;

      private final static double WIDTH = 600;
      private final static double HEIGHT = 300;

          private final StackPane graphicsPane = new StackPane();
          private final Pane drawingPane = new Pane();
          private final Group graphics = new Group();
          
      @Override
      public void start(Stage stage) throws Exception {
              stage.setTitle(getClass().getSimpleName());
              
              BorderPane root = new BorderPane();
              root.setCenter(graphicsPane);
              
              drawingPane.getChildren().add(graphics);
              
              graphicsPane.getChildren().add(drawingPane);
                      
              Scene scene = new Scene(root, WIDTH, HEIGHT);
              stage.setScene(scene);
              stage.show();
              
              graphics.getChildren().add(new WindSockSymbol(new Point2D(100, 100), 0, cache, cacheHint));
              graphics.getChildren().add(new WindSockSymbol(new Point2D(200, 100), 45, cache, cacheHint));
              graphics.getChildren().add(new WindSockSymbol(new Point2D(300, 100), 90, cache, cacheHint));
              graphics.getChildren().add(new WindSockSymbol(new Point2D(400, 100), 135, cache, cacheHint));
              graphics.getChildren().add(new WindSockSymbol(new Point2D(500, 100), 180, cache, cacheHint));
                      
              graphics.getChildren().add(new WindSockSymbol(new Point2D(100, 200), 180, cache, cacheHint));
              graphics.getChildren().add(new WindSockSymbol(new Point2D(200, 200), 225, cache, cacheHint));
              graphics.getChildren().add(new WindSockSymbol(new Point2D(300, 200), 270, cache, cacheHint));
              graphics.getChildren().add(new WindSockSymbol(new Point2D(400, 200), 315, cache, cacheHint));
              graphics.getChildren().add(new WindSockSymbol(new Point2D(500, 200), 360, cache, cacheHint));
      }

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

      }

      package bugs.cache;

      import javafx.geometry.Point2D;
      import javafx.scene.CacheHint;
      import javafx.scene.Group;
      import javafx.scene.effect.DropShadow;
      import javafx.scene.paint.Color;
      import javafx.scene.shape.Polygon;
      import javafx.scene.shape.StrokeType;

      public class WindSockSymbol extends Group {

      private final static boolean FIX_CACHE_PROBLEM = false;

      private final static Color strokeColor = Color.WHITE;

      private final static Color fillColor = Color.CRIMSON;

      private final static DropShadow shadowEffect = new DropShadow();

      static {
      shadowEffect.setRadius(6.0);
      shadowEffect.setOffsetX(0.0);
      shadowEffect.setOffsetY(0.0);
      shadowEffect.setColor(Color.BLACK);
      }

      private final Point2D projectedLocation;

      private final double windDirectionDeg;

      private final Polygon arrow;

      private final CacheHint cacheHint;

      public WindSockSymbol(Point2D labelRefPoint, double windDirectionDeg, boolean cache, CacheHint cacheHint) {
      this.projectedLocation = labelRefPoint;
      this.windDirectionDeg = windDirectionDeg;
      this.cacheHint = cacheHint;
      this.setMouseTransparent(true);

      arrow = new Polygon(-6, -12, -1, +12, 1, +12, +6, -12);
      arrow.setStroke(strokeColor);
      arrow.setStrokeType(StrokeType.OUTSIDE);
      arrow.setStrokeWidth(1.0);
      arrow.setFill(fillColor);
      arrow.setCache(cache);
      arrow.setCacheHint(cacheHint);
      getChildren().add(arrow);

      arrow.setEffect(shadowEffect);

      this.setLayoutX(projectedLocation.getX());
      this.setLayoutY(projectedLocation.getY());

      adjustData();
      }

      private void adjustData() {
      arrow.rotateProperty().set(windDirectionDeg);

      // This is just to fix a JavaFX-Bug. When the cacheHint is SPEED the
      // arrow just disappears if the rotation is 90° or 270°. This does not seem to happen
      // for other cache hints.
      if (FIX_CACHE_PROBLEM && windDirectionDeg % 90 == 0) {
      arrow.setCacheHint(CacheHint.ROTATE);
      } else {
      arrow.setCacheHint(cacheHint);
      }
      }

      }

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

      CUSTOMER SUBMITTED WORKAROUND :
      The only workaround is not to use the cache hint SPEED.

            flar Jim Graham
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: