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

Graphics2D.drawLine sometimes draws lines too long with D3D on Intel HD cards

XMLWordPrintable

    • 2d
    • x86
    • windows_8

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

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows [Version 6.3.9600]

      EXTRA RELEVANT SYSTEM CONFIGURATION :
      Display adapter: Intel(R) Iris(TM) Pro Graphics 5200

      A DESCRIPTION OF THE PROBLEM :
      Horizontal and vertical lines are sometimes drawn one pixel longer than they should be.

      Having noticed this issue myself immediately upon moving to Java 8, I am opening this report with additional information as requested by the comments on https://bugs.openjdk.java.net/browse/JDK-8035278


      ADDITIONAL REGRESSION INFORMATION:
      java version "1.7.0_60"
      Java(TM) SE Runtime Environment (build 1.7.0_60-b19)
      Java HotSpot(TM) 64-Bit Server VM (build 24.60-b09, mixed mode)

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1. Run a program that draws horizontal and/or vertical lines with Graphics2D.drawLine (or methods that uses this method, like drawRect), as in the code provided.

      2. Maximize the window. Observe the horizontal and vertical lines now being drawn one pixel longer than they should be.

      3. Keep resizing and/or moving the window around, and continue to observe: at times, the lines are drawn correctly, and at times, they are drawn one pixel too long.

      Note: step #2 (maximizing) is in no way required to induce the behavior, but the bug consistently occurs the first time the window is maximized.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Lines should be drawn consistently as specified when calling drawLine, regardless of window size (assuming not too small) or position on screen.
      ACTUAL -
      Horizontal and vertical lines are occasionally drawn one pixel longer than specified. As the window is resized or moved around, the lines intermittently change between being drawn correctly and being drawn too long.

      REPRODUCIBILITY :
      This bug can be reproduced often.

      ---------- BEGIN SOURCE ----------
      import javax.swing.*;
      import java.awt.*;

      public class DrawLineBugDemo {

          public static void main(String[] args) {
              SwingUtilities.invokeLater(new Runnable() {
                  public void run() {
                      JFrame f = new JFrame();

                      f.add(new JPanel() {
                          @Override
                          protected void paintComponent(Graphics g) {
                              super.paintComponent(g);

                              // Draw rectangle (buggy: sometimes not a rectangle)
                              g.drawRect(1, 1, 20, 20);

                              // Draw every other pixel (just for visual reference)
                              for (int i = 3; i < 20; i += 2) {
                                  g.drawLine(3, i, 3, i);
                                  g.drawLine(i, 3, i, 3);
                              }

                              // Draw lines of three different lengths
                              for (int i = 0; i < 3; ++i) {
                                  // Horizontal (buggy: for i > 0, sometimes drawn a pixel too long)
                                  int x = 7;
                                  int y = 7 + i * 2;
                                  g.drawLine(x, y, x + i, y);

                                  // Vertical (buggy: for i > 0, sometimes drawn a pixel too long)
                                  x = 13 + i * 2;
                                  y = 7;
                                  g.drawLine(x, y, x, y + i);

                                  // Diagonal (seems okay)
                                  x = 7 + i * 4;
                                  y = 15;
                                  g.drawLine(x, y, x + i, y + i);
                              }
                          }
                      });

                      f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                      f.setSize(150, 100);
                      f.setVisible(true);
                  }
              });
          }
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Problem is not observed when running with -Dsun.java2d.d3d=false

            prr Philip Race
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: