'How do I ensure buffers have been created yet?

I am creating a JFrame in Java on which I want to render some sort of game.

The code I am using to initialize the display is:

frame = new JFrame(displayConfig.title());

frame.setSize(displayConfig.size());
frame.setDefaultCloseOperation(displayConfig.defaultCloseOperation().getValue());
frame.setVisible(true);

frame.createBufferStrategy(2);
bufferStrategy = frame.getBufferStrategy();

Everything around that is working completely fine, however, about every third time I get an IllegalStateException saying that "buffers have not been created yet". How can I ensure that these buffers actually have been created?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source