JDK-4252578 : Program hang in JPanel with large Graphics.drawLine
  • Type: Bug
  • Component: client-libs
  • Sub-Component: 2d
  • Affected Version: 1.2.0
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • OS: windows_95
  • CPU: x86
  • Submitted: 1999-07-08
  • Updated: 2001-11-14
  • Resolved: 2001-11-14
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.
Other
1.4.0 beta3Fixed
Related Reports
Relates :  
Description

Name: rlT66838			Date: 07/08/99


I discovered my Java application to hang while zooming in on
a graphics repaint while drawing lines.

I experimented and determined it happens with
drawLine(x1,y1,x2,y2) when (x2-x1)*(y2-y1)>2^30 or so.

This happens for lines as small as drawLine(0,0,32900,32900).
That's significantly larger than the screen resolution,
but when I'm zooming in on a small part of my image, this
happens quite easily.

Included is an example program. It draws:
drawLine(0,0,rad,rad), with rad=32000 and each time a
"repaint" button is pressed, rad is increased by 100.
Pressing "repaint" 9 times will cause it to fail at rad=32900.

I used this program to test the limits. The error will occur
on any little program with a drawLine which exceeds this limit.

In the very least, the bug should be fixed so the program
doesn't hang - it could just draw nothing.

Thanks!

********************************
//redraw4.java
//7/7/99

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class redraw4 extends JFrame
  implements ActionListener
{
  static redraw4 frame = new redraw4("Drawing test");
  static Dimension d=new Dimension(200,200);

  test t=new test();
  int rad=32000;

  redraw4(String x)
  {
    super(x);

    Container c=getContentPane();
    c.setLayout(new BorderLayout());
    c.add(t,BorderLayout.CENTER);
    Button b=new Button("repaint");
    b.addActionListener(this);
    c.add(b,BorderLayout.NORTH);
  }

  public void actionPerformed(ActionEvent e)
  {
    String arg = e.getActionCommand();
    if (arg.equals("repaint")) t.repaint();
  }

  public static void main(String[] args)
  {
      frame.addWindowListener
      ( //allow application to close with x button.
        new WindowAdapter()
        {
          public void windowClosing(WindowEvent e) {System.exit(0);}
        }
      );

      frame.pack();
      frame.setVisible(true);
  }

  class test extends JPanel
  {
    public test()
    {
      super();
    }

    public Dimension getPreferredSize() { return d; }

    public void draw(Graphics g)
    {
      g.setXORMode(getBackground());
      g.setColor(Color.white);
      g.setPaintMode();
      g.drawString("drawLine(0,0,"+rad+","+rad+")",10,100);
      g.drawLine(0,0,rad,rad);
      rad=(int)(rad+100);
    }

    public void paint(Graphics g)
    {
      super.paint(g);
      draw(g);
    }
  }
}
(Review ID: 85334) 
======================================================================

Comments
CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: merlin-beta3 FIXED IN: merlin-beta3 INTEGRATED IN: merlin-beta3
14-06-2004

WORK AROUND Name: rlT66838 Date: 07/08/99 Manually detect and ignore lines with coordinates that exceed a given length, (or area). ======================================================================
11-06-2004

EVALUATION I've attached a modified version that only uses AWT and exhibits the same behavior. I could only reproduce it when drawing into an Image. I'm reassigning to 2D. Also, the program doesn't hang, it gets stuck in some loop (I'm guessing) and eats up all the CPU. scott.violet@eng 1999-09-16 The test no longer hangs in Merlin 1.4 b70. Part of the problem (when rendering to an offscreen buffer) has been addressed by the fix for 4376103: Java hangs rendering shapes with coords larger than 32k However, on Solaris even though it doesn't hang it doesn't draw a line either when rendering to the screen. Works fine on Win32. dmitri.trembovetski@eng 2001-07-10 This bug has been fixed as a result of the fix for bug 4422006: JTable drawing error introduced in b34 (Solaris/Linux only) Check the bugreport for 4422006 for more info. ###@###.### 2001-11-14
14-11-2001