I have an application that is using a BufferStrategy
created by a JFrame
object to paint shapes. The code is pretty standard, what you would find elsewhere:
// JFrame class
frame.setVisible( true );
frame.createBufferStrategy( 2 );
new Logic( frame.getBufferStrategy() ).loop();
// Logic class
public Logic( BufferStrategy bs ){
this.bs = bs;
}
public void loop(){
// looping should be in another thread
Thread loop = new Thread(new Runnable() {
public void run(){
looooooooop();
}
});
loop.start();
}
Now the looooooooop
function is where the drawing is actually happening:
g = (Graphics2D)bs.getDrawGraphics();
// draw stuff here, leaving out for simplicity
g.dispose();
bs.show();
Toolkit.getDefaultToolkit().sync();
Now the issue is about 75% of the time the application boots up and runs great, the other 25% of the time the frame appears but only the background colour of the frame can be seen, it is like the graphics objects isn't drawing anything on the screen. I have tried debugging and figuring out were this issue is stemming but it is really hard to do so. I am thinking it has something to do with the logic loop running in another thread (maybe this explains the inconsistent nature of the application) but haven't had any luck. Does this issue sound familiar to anyone? Thanks!
Edit - After removing the separate thread this is still happening so it can't be because of that.
Edit 2 - It seems like this is only happening when full screen mode is enabled (with or without the call to setVisible()
):
this.setVisible( true );
if(isFullScreen){
GraphicsEnvironment
.getLocalGraphicsEnvironment()
.getDefaultScreenDevice()
.setFullScreenWindow(this);
}
Is this a known issue or am I missing something? Thanks!
Edit 3 - This is only happening on Ubuntu - verified through brute force. Can't find anything online regarding a bug so I am not sure what to think.