Crash when setting to fullscreen

(topic renamed, new problem further down)

I’m just trying to get my first DropDown menu to run, but I somehow don’t get it done right.

This is the panel it’s attached to:

[xml] <panel id=“resolution” childLayout=“center”>

<control id=“optResolution” name=“dropDown” />


And this is how I try to add an item to it:

[java]Screen screen = nifty.getScreen(“options”);

DropDown<Resolution> dropDown = screen.findNiftyControl(“optResolution”, DropDown.class);

if(dropDown != null)

dropDown.addItem(new Resolution(4, 2)); //<-- in this line the Nullpointerexception is thrown[/java]

The stacktrace is the following:

SCHWERWIEGEND: Uncaught exception thrown in Thread[LWJGL Renderer Thread,5,main]


at de.lessvoid.nifty.controls.dropdown.DropDownControl.addItem(

at main.GameSettings.setNifty(

at main.MainMenuState.initialize(




at com.jme3.system.lwjgl.LwjglAbstractDisplay.runLoop(

at com.jme3.system.lwjgl.LwjglDisplay.runLoop(



Any help would be appreciated :wink:

what is on line 152 in

1 Like
@Sploreg said:
what is on line 152 in

I don't know, but I got it fixed nevertheless by moving the code in the bind() method (the class implements ScreenController), it seems to me like Nifty GUI was still initializing the screens when I used the addItem() method. Thanks for your interest though :)

I ran into two other problems though, the first one is that when I change the resolution at runtime, the current screen is updated correctly, but the others aren't resized. I read that this was mentioned two months before elsewhere, so I just wanted to ask if there is a fix for it out there?

Second, when I try to set the game from windowed mode to fullscreen (by setting the appSettings.setFullscreen(), then setting the Main-app's settings and restarting it), the Application crashes with the following stacktrace:
[java]SCHWERWIEGEND: Uncaught exception thrown in Thread[LWJGL Renderer Thread,5,main]
java.lang.RuntimeException: Unable to find fullscreen display mode matching settings
at com.jme3.system.lwjgl.LwjglDisplay.createContext(
at com.jme3.system.lwjgl.LwjglDisplay.runLoop(
If I activate fullscreen in the launch window it works, and the DefaultScreenDevice also says that fullscreen is supported. What is the problem?

Moreover, is there a way to get all the available resolutions, bitsPerFrame or AA-samples of the OS?

Look at the code of the settings dialog. Something like Display.getGraphicsModes() or similar.

1 Like
@normen said:
Look at the code of the settings dialog. Something like Display.getGraphicsModes() or similar.

I tried getting [java]
GraphicsDevice device = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
DisplayMode[] dms = device.getDisplayModes();[/java]
, but this isn't what I'm looking for.
I also browsed in the AppSettings code, but I could only find the default settings and not all the options. I'm sort of clueless atm, sorry...

Yes that is what you’re looking for :slight_smile: these contain the modes you can set.

1 Like
@normen said:
Yes that is what you're looking for :) these contain the modes you can set.

But I haven't seen something like "displayMode.isFullScreen()", any hint on how I can set the game to fullscreen correctly with that?

That is the fullscreen modes, for windowed you can actually set anything.

1 Like

I now tried

[java] if(fullscreen && device.isFullScreenSupported()) //fullscreen is triggered by a corresponding CheckBox

device.setDisplayMode(device.getDisplayModes()[corresponding()]); //corresponding() returns the index of the chosen resolution. Since the resolutions are added to the DropDown in the same order they are read from the device.getDisplayModes(), this should not be the problem

appSettings.setFullscreen(fullscreen && device.isFullScreenSupported());[/java]

and it throws


at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(

at sun.reflect.DelegatingMethodAccessorImpl.invoke(

at java.lang.reflect.Method.invoke(

at de.lessvoid.nifty.NiftyEventAnnotationProcessor$Subscriber.onEvent(

at org.bushe.swing.event.ThreadSafeEventService.publish(

at org.bushe.swing.event.ThreadSafeEventService.publish(

at de.lessvoid.nifty.Nifty.publishEvent(

at de.lessvoid.nifty.elements.PrimaryClickMouseMethods.publishEvent(

at de.lessvoid.nifty.elements.PrimaryClickMouseMethods.onClick(

at de.lessvoid.nifty.elements.ElementInteractionClickHandler.onClickMouse(

at de.lessvoid.nifty.elements.ElementInteractionClickHandler.process(

at de.lessvoid.nifty.elements.ElementInteraction.process(

at de.lessvoid.nifty.elements.Element.mouseEvent(

at de.lessvoid.nifty.screen.MouseOverHandler.processMouseEvent(

at de.lessvoid.nifty.screen.Screen.forwardMouseEventToLayers(

at de.lessvoid.nifty.screen.Screen.mouseEvent(

at de.lessvoid.nifty.Nifty.forwardMouseEventToScreen(

at de.lessvoid.nifty.Nifty.access$1400(

at de.lessvoid.nifty.Nifty$NiftyInputConsumerImpl.processEvent(

at de.lessvoid.nifty.Nifty$NiftyInputConsumerImpl.processMouseEvent(

at com.jme3.niftygui.InputSystemJme.onMouseButtonEventQueued(

at com.jme3.niftygui.InputSystemJme.forwardEvents(

at de.lessvoid.nifty.Nifty.update(

at com.jme3.niftygui.InputSystemJme.endInput(

at com.jme3.input.InputManager.processQueue(

at com.jme3.input.InputManager.update(



at com.jme3.system.lwjgl.LwjglAbstractDisplay.runLoop(

at com.jme3.system.lwjgl.LwjglDisplay.runLoop(



Caused by: java.lang.UnsupportedOperationException: Cannot change display mode

at java.awt.GraphicsDevice.setDisplayMode(

at sun.awt.Win32GraphicsDevice.setDisplayMode(

at main.GameSettings.onClick(

… 33 more[/java]

Why you want to set the fullscreen displaymode directly? Please read the manual, you have to configure the AppSettings.

1 Like
@normen said:
Why you want to set the fullscreen displaymode directly? Please read the manual, you have to configure the AppSettings.

I don't know exactly what you mean, am I not configuring the AppSettings by setting "appSettings.setFullscreen()"? (Of course I do later in the code use "gameApplication.setSettings(appSettings); gameApplication.restart();".) (looking it up in the documentations and tutorials section lead me to the sentence "you need to provide a key that calls app.stop() to exit the fullscreen view gracefully (default: escape).", but the app becomes restarted anyway, doesn't it?) Interestingly, when started in fullscreen mode, switching between fullscreen and windowed is not a problem (except for the issue that Nifty GUI doesn't scale the other screens, which tends to make some content unreachable)...
@hariboter said:
Of course I do later in the code use "gameApplication.setSettings(appSettings); gameApplication.restart();"

That bold object is the AppSettings I am talking about.
@normen said:
That bold object is the AppSettings I am talking about.

So just to clarify what you mean: [java]
private AppSettings appSettings;
private MyApplication gameApp;
public GameSettings(MyApplication myApp) {
gameApp = myApp; appSettings = myApp.getAppSettings(); //self-written getter
public void onClick(String id, NiftyMousePrimaryClickedEvent event)
if(id == null)

appSettings.setResolution(resolution.width, resolution.height);
appSettings.setFullscreen(fullscreen && device.isFullScreenSupported());
does not configure the appSettings-object? How does it have to be configured then? :?

Well check out its methods…

In terms of despair, here is my examination of the appSettings’ methods:

clear() - does certainly not configure the appSettings object

clone() - doesn’t look like configuration either

containsKey(), containsValue() - looks for settings, but doesn’t configure them

copyFrom() - not useful until I have a configured AppSettings-object to copy from

entrySet() - gives me the values of all fields, but not all the possible values a field can have

equals() - definitely nothing configurable

get() - no configuration component in my eyes

getAudioRenderer(), getBitsPerPixel(), getBoolean(), getClass(), getDepthBits(), getFloat(), getFrameRate(), getFloat(), getFrameRate(), getFrequency(), getHeight(), getIcons(), getInteger(), getSamples(), getSettingsDialogImage(), getStencilBits(), getString(), getTitle(), getWidth(), getHashCode(), isEmpty(), isFullscreen(), isVSync() - all nice, but I don’t see anything returned that would help further to configure fullscreen settings

keySet() - after seeing System.println() of this method it doesn’t give me something to configure also

load() - useful, but not in terms of configuration

mergeFrom() - similar to copyFrom()

notify(), notifyAll() - see load()

put(), putAll(), putBoolean(), putFloat(), putInteger(), putString(), remove() - see examination of the get() methods

save() - see load()

setAudioRenderer(), setBitsPerPixel(), setCustomRenderer(), setDepthBits(), setFrameRate(), setFrequency(), setFullscreen(), setHeight(), setIcons(), setRenderer(), setResolution(), setSamples(), setSettingsDialogImage(), setStencilBits(), setStereo3D(), setTitle(), setUseInput(), setVSync(), setWidth() - I’ve looked through all of them, and except of setFullscreen() (and maybe setResolution() ), I can’t find anything in there that could affect the configuration of fullscreen mode

size(), toString(), useInput(), useJoysticks(), useStereo3D(), values(), wait() - do I have to explain why I don’t think these methods are involved in configuration?

Please don’t get this wrong, I really have no intention to spam or to provoke, it’s just that I really have no idea how to solve the issue :frowning:

Aw, come on … I take the AppSettings Object (which has been preconfigured by the user in the launch window) from the main app, switch to fullscreen by using “appSettings.setFullscreen(true)” during runtime and get a crash. Could please anyone be so kind to tell me what exactly I am doing wrong?

If you mean crash like the stack trace earlier

aused by: java.lang.UnsupportedOperationException: Cannot change display mode
at java.awt.GraphicsDevice.setDisplayMode(
at sun.awt.Win32GraphicsDevice.setDisplayMode(

I guess that the device protests for some reason, I assume you've checked resolution and bit-depth and also that "isDisplayChangeSupported()" returns true, how about the refresh rate? I think it must match the available modes (or you have to explicitly say that you don't care).
I know all this might not be exposed in the app settings but it might explain why it doesn't work.
1 Like
@jmaasing said:
... and also that "isDisplayChangeSupported()" returns true ...

Thanks for the hint! :) I just noticed that "isDisplayChangeSupported()" returns false if the application was started in windowed mode, but returns always true if the application was started in fullscreen mode. Is there some kind of workaround to get the change from windowed to fullscreen mode done nevertheless?

Restart the application :slight_smile: No seriously, I have no clue. I guess you just can’t switch mode without acquiring the native resources correctly, which is about the same as restarting the application in a new window but remembering the application state. It might have something to do with that exclusive-mode thingy in windows also (don’t use windows so I don’t know).

1 Like

If you’re calling setDisplayMode(), you’re doing it wrong.

You change the app settings in the AppSettings object and then call app.restart().

1 Like