Menu to change graphics settings

Hi,



I’m trying to add a menu to the game where you can change the graphics settings. But some settings make it crash with this error:[java]2-nov-2012 21:09:54 com.jme3.app.Application handleError

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

java.lang.NullPointerException

at org.lwjgl.opengl.GL11.glGetError(GL11.java:1278)

at org.lwjgl.opengl.Util.checkGLError(Util.java:57)

at org.lwjgl.opengl.WindowsContextImplementation.setSwapInterval(WindowsContextImplementation.java:113)

at org.lwjgl.opengl.ContextGL.setSwapInterval(ContextGL.java:232)

at org.lwjgl.opengl.DrawableGL.setSwapInterval(DrawableGL.java:86)

at org.lwjgl.opengl.Display.setSwapInterval(Display.java:1117)

at org.lwjgl.opengl.Display.setVSyncEnabled(Display.java:1130)

at com.jme3.system.lwjgl.LwjglDisplay.createContext(LwjglDisplay.java:127)

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

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

at java.lang.Thread.run(Thread.java:662)[/java]



This time, i used the following settings:

Resolution: 1920 x 1080

Fullscreen: true

Color depth: 16

Anti-aliasing: 6

Vsync: true

(The frequency is automatically set to 60 if fullscreen is activated, and to -1 otherwise)



What is really strange about this problem that if I select the exact same settings in the settings dialog, it causes no crash and the game runs fine. However, applying the same settings again in the menu, it still crashes.



This is the code that I use too apply the graphics settings selected in the menu:[java] public void applyGraphics(int width, int height, boolean fullscreen, int bitDepth, int oversampling, boolean sync){

System.out.println("Applying graphics:nResolution: “+width+” x "+height+"nFullscreen: "+fullscreen+"nColor depth: "+bitDepth+"nAnti-aliasing: "+oversampling+

"nVsync: "+sync);

if(fullscreen){

settings.setFrequency(60);

} else {

settings.setFrequency(-1);

}

settings.setResolution(width, height);

settings.setFullscreen(fullscreen);

settings.setBitsPerPixel(bitDepth);

settings.setSamples(oversampling);

settings.setVSync(sync);

app.restart();

this.resulutionChanged = true;

}[/java]

If the setting isn’t supported you cannot set it. Check the code of the settings panel for getting a list of compatible modes.

I tried these settings in the menu:





And this was the result: (together with the stack trace of my previous post)





But when I select these settings at the start:





Then it works.

I don’t see a frequency in your settings. Anyway a NPE is the easiest exception to trace back, just read the stack trace. Also again, you have to check if the system supports that resolution at all.

The frequency is always 60 when fullscreen, and -1 otherwise. And I check which resolutions are supported in the exact same way as the select display settings. I copied the source code and made it work with nifty.

@normen said:
I don't see a frequency in your settings. Anyway a NPE is the easiest exception to trace back, just read the stack trace. Also again, you have to check if the system supports that resolution at all.


I think the problem in this case is that the stack trace is all JME and LWJGL code and that the settings work when set at startup.

I still think it's probably something the OP is doing wrong when he changes settings (does it have to be set back to Application because I don't see that) but the offered debugging methods are probably not going to work in this case.

I've never tried swapping settings at runtime so I don't know if there any hidden gotchas. JME is calling:
Display.setVSyncEnabled(settings.isVSync());

...which then crashes somewhere deep in LWJGL because the ogl error checking is throwing an NPE. To me it sounds like the context is not in a state to check for errors at the time the error check is done. I don't know if this is because JME is not doing the right thing with respect to changing the vsync value in a particular Display state or some other magical incantation that must be performed by the caller.
@beniboy said:
The frequency is always 60 when fullscreen, and -1 otherwise. And I check which resolutions are supported in the exact same way as the select display settings. I copied the source code and made it work with nifty.

No its only so on your computer. If you actually did everything the same, why would it fail? :)
@normen said:
No its only so on your computer. If you actually did everything the same, why would it fail? :)


It would be interesting to hear if this is actually working for anyone else right now. Since it's kind of a bug in JME or LWJGL that this sequence of events causes an NPE then it's possible this is a recent regression... and I don't think many games change display settings at runtime.
@pspeed said:
It would be interesting to hear if this is actually working for anyone else right now. Since it's kind of a bug in JME or LWJGL that this sequence of events causes an NPE then it's possible this is a recent regression... and I don't think many games change display settings at runtime.

TestContextRestart works fine for me.
@normen said:
TestContextRestart works fine for me.


So a potentially fruitful path for the OP debugging would be to also try that test, I guess.

Actually the latest context creation code protects against choosing unsupported samples value, its possible the context restart code does not do that. It sounds like a bug in the restart code…

My graphics card supports 6x samples, it can go up to 8. But what makes this sound more like a bug is that I just commented out the code that changes the settings, so all the apply button in my menu does now is calling app.restart();. This still makes it crash with the same error than when I use the menu.