United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: JDK-6670881 Phantom lines appear when rendering polygons & ellipses with antialiasing OFF
JDK-6670881 : Phantom lines appear when rendering polygons & ellipses with antialiasing OFF

Details
Type:
Bug
Submit Date:
2008-03-04
Status:
Resolved
Updated Date:
2011-02-16
Project Name:
JDK
Resolved Date:
2010-11-11
Component:
client-libs
OS:
linux
Sub-Component:
2d
CPU:
x86
Priority:
P3
Resolution:
Fixed
Affected Versions:
6
Fixed Versions:

Related Reports
Backport:
Relates:
Relates:

Sub Tasks

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

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);
    }
}
                                     
2008-05-20
SUGGESTED FIX

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

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



Hardware and Software, Engineered to Work Together