Buffers Have Not Been Created !!!

I am using a buffer stategy and everything works fine. However once in a while when I run my game I get an error stating "Buffers Have Not Been Created". Is there a way to check the status of the buffer after you create it to see if it's ready before you start using it?
[278 byte] By [sgriffin44a] at [2007-9-28 0:04:23]
# 1
Just so you know, you're not alone on this. It's probably some kind of bug. Perhaps it's something that we should submit. Very rarely my game will crash right as I load it with the same "Buffers Not Created" error.-Jason Thomas.
thedraclea at 2007-7-7 17:18:30 > top of Java-index,Other Topics,Java Game Development...
# 2
I have never had that problem, can you post some code?
JTeena at 2007-7-7 17:18:30 > top of Java-index,Other Topics,Java Game Development...
# 3

The buffer stategy is created with these lines:

game.createBufferStrategy(2);

strategy = game.getBufferStrategy();

The error occurs the first time I try to draw something. The code is fine because this usually works fine but every so often when I run the program I get the "buffers have not been created" error. This happens in all programs where I use this buffer stategy and I think it may be my PC. It's a 500Mh machine and maybe performance is the issue?

sgriffin44a at 2007-7-7 17:18:30 > top of Java-index,Other Topics,Java Game Development...
# 4
in what method are you creating the BufferStrategy?is the Frame from which you are creating the BufferStrategy definitly visible?'sometimes it works, sometimes it doesn't' usually means you've got a threading problem.
Abusea at 2007-7-7 17:18:30 > top of Java-index,Other Topics,Java Game Development...
# 5
Try having a variable called ready. After you make your BufferStrategy, set ready to true. In your paint method, check to see if ready is true, if it isn't the don't do anything, if it is, then paint.
JTeena at 2007-7-7 17:18:30 > top of Java-index,Other Topics,Java Game Development...
# 6

I used a flag to determine when the buffer was created.

This is in the main() method:

GraphicsDevice device = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();

GraphicsConfiguration gc = device.getDefaultConfiguration();

game = new Balloon(gc);

game.setUndecorated(true);

game.setResizable(false);

game.setIgnoreRepaint(true);

device.setFullScreenWindow(game);

game.setVisible(true);

game.createBufferStrategy(2);

strategy = game.getBufferStrategy();

haveBuffer = true;

Then in the run() method the very first thing I do is hold until the buffer is created:

while (! haveBuffer) {} // hold until buffer is created

This problem only occurs once in a while, I can run the program ten times (without changes/recompile) and I may get the error only once.

sgriffin44a at 2007-7-7 17:18:30 > top of Java-index,Other Topics,Java Game Development...
# 7

i am working on an application for which i also use createBufferStrategy() and on the pc i used to write the code everything worked fine but then i continued working on another and i started getting the same kind of errors and in some cases i just got a really distorted view. i discovered that when i create more buffers there is less chance to get the error.

MECHT4NKa at 2007-7-7 17:18:30 > top of Java-index,Other Topics,Java Game Development...
# 8
i just discovered the method also works better if you use Thread.sleep after using the getBufferStrategy method and before you continue to use it.
MECHT4NKa at 2007-7-7 17:18:30 > top of Java-index,Other Topics,Java Game Development...