JDK-6670881 : Phantom lines appear when rendering polygons & ellipses with antialiasing OFF
  • Type: Bug
  • Component: client-libs
  • Sub-Component: 2d
  • Affected Version: 6
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: linux
  • CPU: x86
  • Submitted: 2008-03-04
  • Updated: 2011-02-16
  • Resolved: 2010-11-11
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 6 JDK 7
6u10Fixed 7 b118Fixed
Related Reports
Relates :  
Description
FULL PRODUCT VERSION :
bug appears on

java version "1.6.0"
Java(TM) SE Runtime Environment (build 1.6.0-b105)
Java HotSpot(TM) 64-Bit Server VM (build 1.6.0-b105, mixed mode)

and also:

java version "1.6.0_01"
Java(TM) SE Runtime Environment (build 1.6.0_01-b06)
Java HotSpot(TM) 64-Bit Server VM (build 1.6.0_01-b06, mixed mode)


ADDITIONAL OS VERSION INFORMATION :
Linux 2.6.9-67.ELsmp #1 SMP  x86_64 x86_64 x86_64 GNU/Linux

A DESCRIPTION OF THE PROBLEM :
I am rendering java2D shapes inside a JContainer. If I set rendering hints to turn antialiasing off, then lines which I didn't draw begin appearing alongside the shapes. Whether the lines appear or not is very much dependent on how the shapes are arranged and what size they are (eg. if you draw the shapes in slightly different places, the lines will disappear, or show up in a different place). If the lines do appear, there's only 1 or 2 of them, and they go all the way across the viewport. The lines are usually straight but sometimes slightly curved.  The more shapes being drawn, and the bigger they are, the more likely it is the lines will appear (if some of the shapes are bigger than the viewport, then the lines almost always show up - no matter how you position the shapes). The lines have the same line-thickness, color, etc. as the shapes being drawn.

Turning antialiasing back on makes the problem go away. Unfortunately, I need it off because I'm drawing a lot of shapes and need this to be as fast as possible.

The problem shows up when running on java1.6.0 JVM, regardless of whether the code was compiled using javac 1.6 or 1.5. I was unable to reproduce it on the java1.5.0 JVM.


STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
If you run the provided code, and maximize the JFrame,  you should see lots of concentric ellipses. You should also see one vertical and one horizontal line stretching across the window - these shouldn't be there since the code only draws ellipses.


REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.geom.Ellipse2D;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.WindowConstants;



public class ShapeRenderingTest extends JFrame
{
  public ShapeRenderingTest() {
    JPanel p = new JPanel() {
      
      public void paintComponent ( Graphics g )
      {
        super.paintComponent( g );
        
        ((Graphics2D) g).setRenderingHint( RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);
        
        //((Graphics2D) g).setRenderingHint( RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_SPEED);
        //((Graphics2D) g).setRenderingHint( RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_OFF);
        //((Graphics2D) g).setRenderingHint( RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_SPEED);
        //((Graphics2D) g).setRenderingHint( RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_SPEED);

        //((Graphics2D) g).setClip( 0, 0, getWidth(), getHeight() );
        //((Graphics2D) g).clearRect( 0, 0, getWidth(), getHeight() );
        //((Graphics2D) g).setPaintMode();
        //((Graphics2D) g).setRenderingHint( RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_NORMALIZE );

        int scale = 90;
        int cx = 10;
        int cy = 10;
        
        g.setColor( Color.blue );
        for(int i = 10; i < scale*500; i+=scale) {
          ((Graphics2D) g).draw(new Ellipse2D.Float(cx - i, cy - i, i * 2, i * 2 ));
        }
        
      }
    };
    
    setContentPane( p );
    pack();
  }
  
  public static void main ( String[] args )
  {
    JFrame f = new ShapeRenderingTest();
    f.setDefaultCloseOperation( WindowConstants.DISPOSE_ON_CLOSE );
    f.setVisible( true );
    f.setExtendedState( MAXIMIZED_BOTH );
  }
}

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

CUSTOMER SUBMITTED WORKAROUND :
Turn antialiasing ON using rendering hints.
However, this makes the rendering operation significantly slower, so its not a complete workaround.

Release Regression From : 5.0
The above release value was the last known release where this 
bug was not reproducible. Since then there has been a regression.

Comments
EVALUATION http://hg.openjdk.java.net/jdk7/build/jdk/rev/d9890d8a8159
04-12-2010

SUGGESTED FIX http://sa.sfbay.sun.com/projects/java2d_data/7/6670881.0
29-10-2010

EVALUATION Looks like we have overflow in math calculations inside new non-AA curve renderer. Here is minimized testcase for this problem: import java.awt.*; import java.awt.geom.CubicCurve2D; import javax.swing.*; public class Test extends JPanel { public void paintComponent(Graphics g) { Graphics2D g2d = (Graphics2D) g; g2d.draw(new CubicCurve2D.Float(32780.0f,10.0f, 32780.0f,18108.371f, 18108.371f,32780.0f, 10.0f,32780.0f)); } public static void main(String[] args) { JFrame f = new JFrame(); f.add(new Test()); f.setPreferredSize(new Dimension(1000, 700)); f.pack(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setVisible(true); } }
20-05-2008