Change resolution on runtime

this works perfectly in windowed mode by just calling app.restart().

In fullscreen mode however the screen stays black after a change. It only works if I make the same call twice with a delay:

[java]

app.setSettings(settings);

app.restart();

final ScheduledExecutorService exec = Executors.newSingleThreadScheduledExecutor();

exec.schedule(new Runnable() {

public void run() {

app.restart();

exec.shutdown();

}

}, 200, TimeUnit.MILLISECONDS);[/java]



calling app.reshape() or nifty.resolutionchanged() after the restart doesnt help.

I cannot reproduce this issue



Here’s my code:

[java]

private float time = 0;

private int state = 0;



@Override

public void simpleUpdate(float tpf){

if (state == 0) {

time += tpf;

if (time > 10) {

AppSettings settings = new AppSettings(true);

settings.setFullscreen(true);

settings.setResolution(-1, -1);

setSettings(settings);

restart();

state = 1;

time = 0;

}

}else if (state == 1){

time += tpf;

if (time > 10){

AppSettings settings = new AppSettings(true);

settings.setFullscreen(false);

settings.setResolution(640, 480);

setSettings(settings);

restart();

state = 2;

time = 0;

}

}

}[/java]



After 10 seconds it will enter fullscreen mode, then 10 seconds later back into windowed 640x480.

I tried several tests with it and they worked fine.

It only happens when switching from one resolution in fullscreen mode to another resolution in fullscreen mode.

I was able to reproduce this bug but it seems to happen only under certain resolution combinations, and sometimes it doesn’t happen at all…

I wonder if it is a race condition of some sort



EDIT: It is really strange but I can see the frames are still being pushed yet… Sometimes I can click the view and the “focus” comes back on and it starts working again. Also you can minimize then maximize and it still will work

I encountered something similar once.

Its when the wanted Settings are not supported by the graphicscard. For example if there are solutions available only in fullscreen and one tries to force them under window mode.



There should be an exception thrown. which tells something like this

I am filtering the available resolutions through the following code (just for testing purposes):

[java] List<DisplayMode> displayModes = Arrays.asList(Display.getAvailableDisplayModes());

for (DisplayMode dm : displayModes) {

if ((dm.getFrequency() == 60) && (dm.getBitsPerPixel() == 32) && (dm.isFullscreenCapable())) {

if ((dm.getWidth() == 1024) || (dm.getWidth() == 1280) || (dm.getWidth() == 1680) || (dm.getWidth() == 1920))

resolutionDropDown.addItem(dm.getWidth() + "x" + dm.getHeight());

}

}[/java]

This way all available resolutions should be supported.

As stated it does work if I call restart() twice with a short delay.