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

Phantom lines appear when rendering polygons & ellipses with antialiasing OFF

    XMLWordPrintable

    Details

    • Subcomponent:
      2d
    • Introduced In Version:
      6
    • Resolved In Build:
      b118
    • CPU:
      x86
    • OS:
      linux

      Backports

        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.

          Attachments

            Issue Links

              Activity

                People

                Assignee:
                avu Alexey Ushakov
                Reporter:
                ndcosta Nelson Dcosta (Inactive)
                Votes:
                0 Vote for this issue
                Watchers:
                0 Start watching this issue

                  Dates

                  Created:
                  Updated:
                  Resolved:
                  Imported:
                  Indexed: