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?
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.
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.