Skip to content

Crash when going full screen #2

Description

@vafada

I'm seeing a crash when going to full screen mode via F12.

Exception in thread "Thread-4" java.lang.IllegalStateException: Component must have a valid peer
	at java.desktop/java.awt.Component$FlipBufferStrategy.flip(Component.java:4171)
	at java.desktop/java.awt.Component$FlipBufferStrategy.show(Component.java:4298)
	at wolf3d.infra.GameCanvas$MainLoop.run(GameCanvas.java:118)
	at java.base/java.lang.Thread.run(Thread.java:1575)

and

Exception in thread "Thread-4" java.lang.IllegalStateException: Buffers have not been created
	at java.desktop/sun.awt.X11.XComponentPeer.getBackBuffer(XComponentPeer.java:1143)
	at java.desktop/java.awt.Component$FlipBufferStrategy.getBackBuffer(Component.java:4144)
	at java.desktop/java.awt.Component$FlipBufferStrategy.flip(Component.java:4164)
	at java.desktop/java.awt.Component$FlipBufferStrategy.show(Component.java:4298)
	at wolf3d.infra.GameCanvas$MainLoop.run(GameCanvas.java:118)
	at java.base/java.lang.Thread.run(Thread.java:1575)

You can easily reproduce this by spamming clicking on F12 if you don't see the issue the first time.

I believe the issue has something to do with threading.

the method to go to full screen disposes the window:

public void setFullscreenMode() {
dispose();
setUndecorated(true);
setVisible(true);
//System.out.println("fullscreen supported: "
// + gd.isFullScreenSupported());
gd.setFullScreenWindow(this);
gd.setDisplayMode(fullscreenDisplayMode);
gameCanvas.updateAspectRatioDimension();
gameCanvas.requestFocus();
hideMouseCursor();
}

but the main game loop is trying to access the buffer, these are the two places i see crashing:

Graphics2D g = (Graphics2D) bs.getDrawGraphics();

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions