The reproducer is: https://bugzilla.redhat.com/attachment.cgi?id=417597
I have attached a JTreg test version of it.
----- Original Message -----
From: "Andrew John Hughes" <ahug...@redhat.com>
To: "Denis Lila" <dl...@redhat.com>
Cc: 2d-dev@openjdk.java.net
Sent: Wednesday, June 16, 2010 11:18:42 AM GMT -05:00 US/Canada Eastern
Subject: [PATCH FOR REVIEW] Fix for bug where long dashed lines can make
graphics go black.
On 9 June 2010 23:49, Denis Lila <dl...@redhat.com> wrote:
> Hello.
>
> I think I have a fix for this bug:
> https://bugzilla.redhat.com/show_bug.cgi?id=597227
>
> The bug was caused by a few integer overflows in sun/java2d/pisces/Dasher.java
> and sun/java2d/pisces/Stroker.java which would cause the whole container to
> fill up with whatever colour the line had. Dasher.java was prone to 2
> overflows:
> one when computing the x and y coordinate lengths of the line at hand, and
> another which actually happened in PiscesMath.hypot(int,int). I fixed these
> two by turning the variables into longs and using PiscesMath.hypot(long,long).
>
> Stroker.java was only prone to overflows when drawing end caps or when adding
> offsets to points. I fixed these by making sure lineTo and moveTo never moved
> too close to the boundaries set by Integer.MAX_VALUE and Integer.MIN_VALUE.
>
> I welcome any feedback.
>
> Thank you,
> Denis Lila.
Webrev against 2d: http://cr.openjdk.java.net/~andrew/rh597227/
Do you have a reproducer for this? It would help if that was included
as a JTreg test.
--
Andrew :-)
Free Java Software Engineer
Red Hat, Inc. (http://www.redhat.com)
Support Free Java!
Contribute to GNU Classpath and the OpenJDK
http://www.gnu.org/software/classpath
http://openjdk.java.net
PGP Key: 94EFD9D8 (http://subkeys.pgp.net)
Fingerprint: F8EF F1EA 401E 2E60 15FA 7927 142C 2591 94EF D9D8
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
/**
* @test 1.1 10/06/16
* @bug 0597227
* @run applet/manual=yesno DrawLine.html
* @summary Check if window goes black.
*/
public class DrawLine extends JApplet {
public void init() {}
public void start() {
final JPanel panel = new JPanel();
JButton button = new JButton("button");
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Graphics2D gc = (Graphics2D)panel.getGraphics();
BasicStroke orig = (BasicStroke)gc.getStroke();
gc.setStroke(
new BasicStroke(
1,
2,
0,
1,
new float[] {9f, 9f},
0
)
);
int nPoints = 36;
int[] xPoints = new int[nPoints];
int[] yPoints = new int[nPoints];
int maxVal = 100000;
for (int i = 0; i < nPoints; i++) {
xPoints[i] = (int)((Math.random() - 0.5) * maxVal);
yPoints[i] = (int)((Math.random() - 0.5) * maxVal);
gc.drawLine(0, 0, xPoints[i], yPoints[i]);
}
gc.setStroke(orig);
}});
panel.add(button);
this.add(panel);
}
public static void main(final String[] args) {
JFrame frame = new JFrame("DrawLine");
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
JApplet ap = new DrawLine();
ap.init();
ap.start();
frame.add("Center", ap);
frame.pack();
frame.setVisible(true);
}
}
Push the button at the top of the applet.
If the window is filled with black, fail.
If some dashed lines are drawn, emanating from the top left corner, pass.