BufferStrategy

Hi there.

I use the following code for entering fullscreen mode via visible=true and exiting the game with visible=false
My problem is, that it doesn’t exit but rather leaves a white screen that doesn’t react to anything else than killing it with the taskmanager from windows.
Any suggestions on how to solve this ?

public void showMe(boolean visible) {
		if(visible){
			setIgnoreRepaint(true);
			setUndecorated(true);
			device.setFullScreenWindow(this);
			int depth = device.getDisplayMode().getBitDepth();
			int refresh = device.getDisplayMode().getRefreshRate();
			Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
			gg.setFrameSize(d);
			try{
				device.setDisplayMode(new DisplayMode(d.width, d.height, depth, refresh));
				createBufferStrategy(numJavaFullScreenBuffers);
				bufferStrategy = getBufferStrategy();
			}catch(Exception e){
				e.printStackTrace();
			}
			requestFocus();
		}else{
			device.setFullScreenWindow(null);
			setVisible(false);
                        System.exit(0);
		}
	}

Thanks for any help, I appreciate it.

I suppose

device.setFullScreenWindow(null);

throws an exception here. You should debug the code and find out whether

System.exit(0);

is called or not.

By the way, what’s the class of device?

The class of device is GraphicsDevice obtained from

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

and I’m using this inside a subclass of java.awt.Frame.

And you’re right, the first command throws an Exception.

Should I replace

 
device.setFullScreenWindow(null);

with

 
device.setFullScreenWindow(displayMode);

where displayMode is obtained from the device before going into fullscreenmode ?
This works in closing the window now, but the program still doesn’t finish.
I get the following console output:

[quote]Mai 11, 2016 6:04:29 PM java.util.prefs.WindowsPreferences
WARNING: Could not open/create prefs root node Software\JavaSoft\Prefs at root 0
x80000002. Windows RegCreateKeyEx(…) returned error code 5.
[/quote]

Well, it would be very interesting, what the Exception says ???
And you could check wether device is null or not.

Have a look at the API. I suppose setFullScreenWindow(null); is the right decision.
You should probably also read this Tutorial about the Full-Screen Exclusive Mode.

I’m sorry, I should’ve written that as well.

With

device.setFullScreenWindow(null);

I get the following exception:

[quote]Exception in thread “AWT-EventQueue-0” java.lang.IllegalArgumentException: Invalid display mode
at sun.awt.Win32GraphicsDevice.setDisplayMode(Unknown Source)
at Game.Graphics.GraphicsEngine.showMe(GraphicsEngine.java:132)
[/quote]
As for the device it’s definitly not null. Debug inspection says, it’s a [quote]D3DGraphicsDevice[screen=0]
[/quote]
I read the tutorial you mentioned a few years ago already, which led to my previous code.
In the past I didn’t run into those kind of problems.
Some years have gone by without me using the fullscreen exclusive mode.
I’ll go over the tutorial again tomorrow, to see if anything’s got changed or updated.

Thank you for your help.
I’m a bit confused right now :wink:

Now this isn’t funny anymore…
I compiled and run the DisplayModeTest from
https://docs.oracle.com/javase/tutorial/displayCode.html?code=https://docs.oracle.com/javase/tutorial/extra/fullscreen/examples/DisplayModeTest.java
and it doesn’t exit either.
The fullscreenmode seems to be exited but there’s still a frameicon in my taskbar and I
have something like an invisible or transparent frame above my eclipse which takes no inputs.
Really awkward. :clue:

Maybe I should add something about my environment here:

Windows 7 Home Premium
Java 8 Update 91 (Build 1.8.0_91-b14)
Eclipse Version: Luna Service Release 2 (4.4.2)

on a Phenom II X4, 8GB RAM, NVidia 465 GTX

Something else I should post in addition ?

Okay this is really not funny anymore :smiley: The DisplayModeTest works well here.

My suggestion is to remove whole java, eclipse, … and then reinstall everything.

Never ever do this:


device.setDisplayMode(new DisplayMode(d.width, d.height, depth, refresh));

Java AWT just cannot cope with your own DisplayMode instances. Pick one from the DisplayMode[] reported by your device. Even a completely identical manually created instance will not function well. This has been the case for over a decade, learn from my mistakes. :point:

It might not even be related to the issue you are facing, just fix it anyway :slight_smile:

I have this code with me (it’s even working in 2016, but originally I wrote it in 2012). http://pastebin.com/TABWDFUE

Ask me if you have any questions regarding it.

You have 3 bugs in that code:

  1. You check for a displaymode with 32 bit color depth, as opposed to the color depth of the current displaymode. Just use device.getDisplayMode() as a reference, or use it directly. No need to mess with Toolkit.
  2. You ‘center’ the mouse by dividing width and height by… four.
  3. You set the displaymode N times in rapid succession when there are N displaymodes with the same width, height and bit-depth, but different refreshrates. N is likely to be >= 4

Eagle eyes! I knew there were some bugs, but this was written in the early days when I started programming. This is already dead code, I’m not going to use it again. Just posted here so something would be helpful to the OP.

But you were awesome Riven, it is a great find.

I fixed it. Thanks a lot.
Every suggestion to correct or optimize my code means a lot to me as I’m currently learning a lot of new stuff and trying to make a project
not as quick and dirty as before but rather elaborate.

[quote]Okay this is really not funny anymore Cheesy The DisplayModeTest works well here.

My suggestion is to remove whole java, eclipse, … and then reinstall everything.
[/quote]
I reinstalled the newest version of both and it didn’t have any effect on the outcome.
But it’s not bad to have eclipse mars instead of luna now :wink:

[quote]I have this code with me (it’s even working in 2016, but originally I wrote it in 2012). http://pastebin.com/TABWDFUE

Ask me if you have any questions regarding it.
[/quote]
And I had a look at your code, updating my frameclass as much as possible including Rivens corrections.

But the result for my own as well as Oracles tutorial class is still the same, a fully transparent frame which is only removeable by killing the process the hard way.

How many Monitors are you running on? The Oracle code is not suitable for more than 1 monitor