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” />

</panel>[/xml]

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]

java.lang.NullPointerException

at de.lessvoid.nifty.controls.dropdown.DropDownControl.addItem(DropDownControl.java:152)

at main.GameSettings.setNifty(GameSettings.java:72)

at main.MainMenuState.initialize(MainMenuState.java:80)

at com.jme3.app.state.AppStateManager.initializePending(AppStateManager.java:219)

at com.jme3.app.state.AppStateManager.update(AppStateManager.java:249)

at com.jme3.app.SimpleApplication.update(SimpleApplication.java:241)

at com.jme3.system.lwjgl.LwjglAbstractDisplay.runLoop(LwjglAbstractDisplay.java:149)

at com.jme3.system.lwjgl.LwjglDisplay.runLoop(LwjglDisplay.java:182)

at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:223)

at java.lang.Thread.run(Thread.java:662)



Any help would be appreciated :wink:

what is on line 152 in DropDownControl.java?

1 Like
@Sploreg said:
what is on line 152 in DropDownControl.java?


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(LwjglDisplay.java:79)
at com.jme3.system.lwjgl.LwjglDisplay.runLoop(LwjglDisplay.java:174)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:223)
at java.lang.Thread.run(Thread.java:662)[/java]
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

[java]java.lang.reflect.InvocationTargetException

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

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

at java.lang.reflect.Method.invoke(Method.java:597)

at de.lessvoid.nifty.NiftyEventAnnotationProcessor$Subscriber.onEvent(NiftyEventAnnotationProcessor.java:118)

at org.bushe.swing.event.ThreadSafeEventService.publish(ThreadSafeEventService.java:980)

at org.bushe.swing.event.ThreadSafeEventService.publish(ThreadSafeEventService.java:920)

at de.lessvoid.nifty.Nifty.publishEvent(Nifty.java:193)

at de.lessvoid.nifty.elements.PrimaryClickMouseMethods.publishEvent(PrimaryClickMouseMethods.java:53)

at de.lessvoid.nifty.elements.PrimaryClickMouseMethods.onClick(PrimaryClickMouseMethods.java:26)

at de.lessvoid.nifty.elements.ElementInteractionClickHandler.onClickMouse(ElementInteractionClickHandler.java:105)

at de.lessvoid.nifty.elements.ElementInteractionClickHandler.process(ElementInteractionClickHandler.java:70)

at de.lessvoid.nifty.elements.ElementInteraction.process(ElementInteraction.java:79)

at de.lessvoid.nifty.elements.Element.mouseEvent(Element.java:1405)

at de.lessvoid.nifty.screen.MouseOverHandler.processMouseEvent(MouseOverHandler.java:93)

at de.lessvoid.nifty.screen.Screen.forwardMouseEventToLayers(Screen.java:360)

at de.lessvoid.nifty.screen.Screen.mouseEvent(Screen.java:336)

at de.lessvoid.nifty.Nifty.forwardMouseEventToScreen(Nifty.java:266)

at de.lessvoid.nifty.Nifty.access$1400(Nifty.java:73)

at de.lessvoid.nifty.Nifty$NiftyInputConsumerImpl.processEvent(Nifty.java:1370)

at de.lessvoid.nifty.Nifty$NiftyInputConsumerImpl.processMouseEvent(Nifty.java:1329)

at com.jme3.niftygui.InputSystemJme.onMouseButtonEventQueued(InputSystemJme.java:161)

at com.jme3.niftygui.InputSystemJme.forwardEvents(InputSystemJme.java:236)

at de.lessvoid.nifty.Nifty.update(Nifty.java:248)

at com.jme3.niftygui.InputSystemJme.endInput(InputSystemJme.java:92)

at com.jme3.input.InputManager.processQueue(InputManager.java:787)

at com.jme3.input.InputManager.update(InputManager.java:851)

at com.jme3.app.Application.update(Application.java:598)

at com.jme3.app.SimpleApplication.update(SimpleApplication.java:233)

at com.jme3.system.lwjgl.LwjglAbstractDisplay.runLoop(LwjglAbstractDisplay.java:149)

at com.jme3.system.lwjgl.LwjglDisplay.runLoop(LwjglDisplay.java:182)

at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:223)

at java.lang.Thread.run(Thread.java:662)

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

at java.awt.GraphicsDevice.setDisplayMode(GraphicsDevice.java:356)

at sun.awt.Win32GraphicsDevice.setDisplayMode(Win32GraphicsDevice.java:389)

at main.GameSettings.onClick(GameSettings.java:92)

… 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
...
}
...
@NiftyEventSubscriber(pattern="opt.*")
public void onClick(String id, NiftyMousePrimaryClickedEvent event)
{
if(id == null)
return;

if(id.equals("optApply"))
{
appSettings.setResolution(resolution.width, resolution.height);
appSettings.setFullscreen(fullscreen && device.isFullScreenSupported());
gameApp.setSettings(appSettings);
gameApp.restart();
}[/java]
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(GraphicsDevice.java:356)
at sun.awt.Win32GraphicsDevice.setDisplayMode(Win32GraphicsDevice.java:389)


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