Here's the test case.
Try running it, switching users and logging back in. In some situations, not all, the code will keep printing out contents lost. To avoid getting stuck in an infinite lop the code exits after the 10th paint.
Both Chet and myself have been able to reproduce this.
import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import javax.swing.*;
public class BSTest extends Frame {
private int GRID_SIZE = 30;
public static void main(String[] args) {
BSTest f = new BSTest();
f.setBounds(0, 0, 200, 200);
f.show();
}
private BufferStrategy bs;
public BSTest() {
}
private int paintIndex = 0;
public void paint(Graphics g) {
System.err.println(paintIndex + " painting");
if (paintIndex++ > 10) {
System.exit(0);
}
if (bs == null) {
bs = createBufferStrategy();
Graphics g2 = bs.getDrawGraphics();
drawGrid(g2);
g2.dispose();
}
Graphics g2 = bs.getDrawGraphics();
if (bs.contentsRestored()) {
System.err.println("contents restored, forcing repaint");
repaint();
}
else if (bs.contentsLost()) {
System.err.println("contents lost, forcing repaint");
repaint();
}
else {
System.err.println("all good");
drawGrid(g2);
bs.show();
if (bs.contentsLost()) {
System.err.println("\tcontents lost2, forcing repaint");
repaint();
}
}
g2.dispose();
}
private void drawGrid(Graphics g) {
g.setColor(Color.WHITE);
g.fillRect(0, 0, getWidth(), getHeight());
Insets insets = getInsets();
FontMetrics fm = g.getFontMetrics();
int ascent = fm.getAscent();
g.setColor(Color.BLACK);
for (int x = 0; x < getWidth(); x += GRID_SIZE) {
g.drawLine(x, 0, x, getHeight());
g.drawString(Integer.toString(x), x, ascent +
(insets.top / GRID_SIZE) * GRID_SIZE);
}
int stringXOrigin = getInsets().left;
for (int y = 0; y < getHeight(); y += GRID_SIZE) {
g.drawLine(0, y, getWidth(), y);
g.drawString(Integer.toString(y), stringXOrigin, y + ascent);
}
}
private BufferStrategy createBufferStrategy() {
BufferCapabilities caps = new BufferCapabilities(
new ImageCapabilities(true),
new ImageCapabilities(true),
null);
try {
createBufferStrategy(2, caps);
} catch (AWTException ae) {
System.out.println("ae: " + ae);
}
return getBufferStrategy();
}
}
###@###.### 2005-03-23 18:46:49 GMT