Settings Change Crash

So i’ve been doing a lot of beta testing for Spoxel lately and i’ve been getting a ton of bug reports related to changing graphics settings. Whenever a player changes the options in Spoxel it reapplies everything. I’ve had spotty reports of it happening in the main menu, but i’ve been consistently able to cause it to happen in game and only when the in full screen mode. The players get the following exception:

[2018-03-02 15:53:38] [SEVERE ] [com.jme3.app.LegacyApplication] Uncaught exception thrown in Thread[jME3 Main,5,main] 
org.lwjgl.opengl.OpenGLException: Invalid value (1281)
	at org.lwjgl.opengl.Util.checkGLError(Util.java:59)
	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:1129)
	at org.lwjgl.opengl.Display.setVSyncEnabled(Display.java:1142)
	at com.jme3.system.lwjgl.LwjglDisplay.createContext(LwjglDisplay.java:130)
	at com.jme3.system.lwjgl.LwjglDisplay.runLoop(LwjglDisplay.java:184)
	at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:232)
	at java.lang.Thread.run(Thread.java:748)

I was able to debug it slightly and found that the value it was attempting to set was vsync. The relevant section of code I am calling is:

    AppSettings set = Voxelcraft.getInstance().getAppSettings();
    set.putFloat("musicVolume", musicVolume);
    set.putFloat("soundVolume", soundVolume);
    set.setFullscreen(!windowed);
    set.putBoolean("borderless", borderless);
    set.putFloat("gammaValue", gamma);
    set.setHeight(dispSet.height);
    set.setWidth(dispSet.width);
    set.putString("textureDetail", td.getSelection());
    set.putString("lightingDetail", ld.getSelection());
    set.putString("particleDetail", pd.getSelection());
    //set.putInteger("Samples", Integer.parseInt(samp.getSelection()));
    set.putBoolean("fxaa", fxaa);
    set.putBoolean("ssao", ssao);
    set.putBoolean("bloom", bloom);
    set.putBoolean("fogEffects", fog);
    set.setVSync(vsync);
    set.putBoolean("showHealthbars", healthbars);
    System.setProperty("org.lwjgl.opengl.Window.undecorated", borderless ? "true" : "false");

    app.applyAppSettings(set);
    nifty.getSoundSystem().setMusicVolume(musicVolume);
    nifty.getSoundSystem().setSoundVolume(soundVolume);
    nifty.enableAutoScaling(dispSet.width, dispSet.height);
    nifty.resolutionChanged();
    nifty.getRenderEngine().displayResolutionChanged();
    //nifty.gotoScreen("optionsMenu");

    applyKeybindChanges();

    // if we are running apply graphics changes
    if (Voxelcraft.hasState(GameState.class)) {
      GameState gs = Voxelcraft.getState(GameState.class);
      gs.updateGraphicsFilters();
    }


    element.setFocus();

    screen.getFocusHandler().resetFocusElements();
    nifty.resetMouseInputEvents();

I’m pretty much at my wits end on this one. I’ve toyed around with just not letting players change things like the resolution and vsync in game but i’ve had a few reports of it happening in the main menu now. Any ideas what could be going on?

I gave up on this a long time ago and went with a custom launcher that has a selection for resolution, vsync, AA, frequency and windowed/borderless. Not ideal, but hey Bethesda does it that way too so ¯\_(ツ)_/¯

That is pretty… unsettling. I assume it has something to do with something being rendered at the time the change happens, but even making sure it happens in the main thread doesn’t help. It annoys the crap out of me whenever games have launchers and you can’t change the settings in game. So I would really like to avoid that.

It seems like it is running into this error because jmonkey is still rendering something at the time. Is there a way to stop the opengl context and prevent rendering for awhile when you change settings?

Have you tried Lemur to see if that makes a diff?

This crash really has nothing to do with the GUI lib. It happens much less often in the main menu when it is just nifty rendering for example but I’ve had reports from a handful of players that they can still get the crash.