-
Bug
-
Resolution: Duplicate
-
P1
-
None
-
1.1
-
None
-
sparc
-
solaris_2.5
Name: mc57594 Date: 01/20/97
(code follows) I have a modal dialog box containing some buttons.
One of these buttons opens another modal dialog box which contains a picture
(a Canvas) and a button to close the dialog box. Clicking the dismissal
button results in a segmentation fault. This segmentation fault does not
occur every time, however. The code attached below is a simplified piece
of code which exibits the problem. I ran this piece of code several times
as it appears below. The segmentation faults occurred on the 30th, 3rd,
16th, and 68th times the second dialog is dismissed. However, it seems
that the more things there are in this second dialog, or the bigger they
are (for example, more functionality such as listening to events), the fewer
dismissals are required to cause this segmentation fault.
*********************
TestFrame.java
*********************
import java.awt.*;
import java.awt.event.*;
public class TestFrame extends Frame implements ActionListener {
public void actionPerformed(ActionEvent e) {
System.out.println(e.getActionCommand());
if (e.getActionCommand().equals("OK"))
((Dialog)((Component)e.getSource()).getParent()).dispose();
else if (e.getActionCommand().equals("other dialog")) {
Dialog d = new Dialog(this,"second",true);
d.setLayout(new GridLayout(2,1));
ExponentialDistribution ed = new ExponentialDistribution();
d.add(ed);
Button b = new Button("OK");
b.addActionListener(this);
d.add(b);
d.resize(400,400);
d.show();
b.removeActionListener(this);
}
}
public static void main(String[] args) {
TestFrame f = new TestFrame();
f.resize(100,100);
f.show();
Dialog d = new Dialog(f,"first",true);
d.setLayout(new GridLayout(2,1));
Button b = new Button("other dialog");
b.addActionListener(f);
d.add(b);
b = new Button("OK");
b.addActionListener(f);
d.add(b);
d.resize(100,100);
d.show();
}
}
*****************
ExponentialDistribution.java
*****************
import java.awt.*;
import java.awt.event.*;
public class ExponentialDistribution extends Canvas {
private double _mu;
private int lowx;
private int highx;
private int lowy;
private int highy;
public ExponentialDistribution() {
_mu = 5;
}
public void paint(Graphics g) {
Dimension d = size();
lowx = d.width / 10;
highx = d.width - lowx;
lowy = d.height / 10;
highy = d.height - lowy;
// draw a box for the border. this illustrates the margins only, and will go away.
// g.setColor(Color.blue);
// g.drawRect(lowx,lowy,highx-lowx,highy-lowy);
g.setColor(Color.black);
g.drawLine(lowx,highy,highx,highy);
g.drawLine(lowx,lowy,lowx,highy);
g.drawString("0",lowx - 4, highy + 15);
g.drawString("Mean: " + _mu, lowx + 5, lowy - 5);
g.setColor(Color.red);
int height = highy - lowy;
double lasty = 1/_mu * height * 10;
for (int i = 1; i*2 + lowx< highx; i++) {
double yval = (1 / _mu) * Math.exp(-i/_mu);
yval*=10;
yval *= height;
if ((int)Math.floor(highy- lasty -1) < lowy)
if ((int)Math.floor(highy - yval - 1) < lowy)
g.drawLine((i-1)*2 + lowx, lowy, i*2 + lowx, lowy);
else
g.drawLine((i-1)*2 + lowx, lowy, i*2 + lowx, (int)Math.floor(highy-yval-1));
else
if ((int)Math.floor(highy - yval - 1) < lowy)
g.drawLine((i-1)*2 + lowx, (int)Math.floor(highy-lasty-1), i*2 + lowx, lowy);
else
g.drawLine((i-1)*2 + lowx, (int)Math.floor(highy-lasty-1), i*2 + lowx, (int)Math.floor(highy-yval-1));
lasty = yval;
}
}
}
======================================================================
- duplicates
-
JDK-4024711 Return from Modal Dialog in AWT causes seg violation
-
- Closed
-