Bug Database
Bug Detail
Quick Lists
Top 25 Bugs
Top 25 RFE's
Recently Closed Bugs
Printable Page Printable Page


Bug Database
Bug ID: 4252578
Votes 7
Synopsis Program hang in JPanel with large Graphics.drawLine
Category java:classes_2d
Reported Against 1.2
Release Fixed 1.4(merlin-beta3)
State 10-Fix Delivered, bug
Priority: 4-Low
Related Bugs 4376103
Submit Date 08-JUL-1999
Description




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) 
======================================================================
Work Around




Manually detect and ignore lines with coordinates that exceed
a given length, (or area).
======================================================================
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.
  xxxxx@xxxxx   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.

  xxxxx@xxxxx   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.

  xxxxx@xxxxx   2001-11-14
Comments
  
  Include a link with my name & email   

Submitted On 27-OCT-2000
rammi
Wow, this bug is still in Java 1.3 and lingers here already
more than a year. But I cannot complain, most of Java is
running well and I haven't paid fo it. I've written a
workaround where I implemented the clipping for lines and
polylines on my own. It can be found under
<a href="www.caff.de/clip/">www.caff.de/clip/</a> .
Regards, 
Rammi


Submitted On 26-FEB-2001
xorxor
This is probably a duplicate of bug 4265778.  Please 
consider moving these votes to that bug.



PLEASE NOTE: JDK6 is formerly known as Project Mustang