jmonkeyengine
jmonkeyengine copied to clipboard
LWJGLException when switching from full-screen to windowed context
If I start a JME application in windowed mode, I can switch to full-screen mode at any time, provided my settings match one of those supported by my graphic adapter.
However, if I start in full-screen mode, any attempt to switch to windowed mode crashes the application. I see this issue with both JME 3.1.0-stable and JME 3.2.0-stable
Here is my test app:
package mygame;
import com.jme3.app.SimpleApplication;
import com.jme3.input.KeyInput;
import com.jme3.input.controls.ActionListener;
import com.jme3.input.controls.KeyTrigger;
public class Main extends SimpleApplication {
public static void main(String[] args) {
Main app = new Main();
app.start();
}
@Override
public void simpleInitApp() {
inputManager.addMapping("goWindowed", new KeyTrigger(KeyInput.KEY_P));
ActionListener listener = new ActionListener() {
@Override
public void onAction(String name, boolean keyPressed, float tpf) {
if (name.equals("goWindowed") && keyPressed) {
goWindowed();
}
}
};
inputManager.addListener(listener, "goWindowed");
}
void goWindowed() {
settings.setFullscreen(false);
setSettings(settings);
restart();
}
}
Here is typical output:
Jan 11, 2018 2:14:48 PM com.jme3.system.JmeDesktopSystem initialize
INFO: Running on jMonkeyEngine 3.1-stable
* Branch: HEAD
* Git Hash: af04bf9
* Build Date: 2017-02-13
Jan 11, 2018 2:14:49 PM com.jme3.system.lwjgl.LwjglContext printContextInitInfo
INFO: LWJGL 2.9.3 context running on thread jME3 Main
* Graphics Adapter: nvd3dumx,nvwgf2umx,nvwgf2umx
* Driver Version: 21.21.13.7633
* Scaling Factor: 1
Jan 11, 2018 2:14:50 PM com.jme3.renderer.opengl.GLRenderer loadCapabilitiesCommon
INFO: OpenGL Renderer Information
* Vendor: NVIDIA Corporation
* Renderer: GeForce GT 545/PCIe/SSE2
* OpenGL Version: 4.5.0 NVIDIA 376.33
* GLSL Version: 4.50 NVIDIA
* Profile: Compatibility
Jan 11, 2018 2:14:50 PM com.jme3.audio.openal.ALAudioRenderer initOpenAL
INFO: Audio Renderer Information
* Device: OpenAL Soft
* Vendor: OpenAL Community
* Renderer: OpenAL Soft
* Version: 1.1 ALSOFT 1.15.1
* Supported channels: 64
* ALC extensions: ALC_ENUMERATE_ALL_EXT ALC_ENUMERATION_EXT ALC_EXT_CAPTURE ALC_EXT_DEDICATED ALC_EXT_disconnect ALC_EXT_EFX ALC_EXT_thread_local_context ALC_SOFT_loopback
* AL extensions: AL_EXT_ALAW AL_EXT_DOUBLE AL_EXT_EXPONENT_DISTANCE AL_EXT_FLOAT32 AL_EXT_IMA4 AL_EXT_LINEAR_DISTANCE AL_EXT_MCFORMATS AL_EXT_MULAW AL_EXT_MULAW_MCFORMATS AL_EXT_OFFSET AL_EXT_source_distance_model AL_LOKI_quadriphonic AL_SOFT_buffer_samples AL_SOFT_buffer_sub_data AL_SOFTX_deferred_updates AL_SOFT_direct_channels AL_SOFT_loop_points AL_SOFT_source_latency
Jan 11, 2018 2:14:50 PM com.jme3.audio.openal.ALAudioRenderer initOpenAL
WARNING: Pausing audio device not supported.
Jan 11, 2018 2:14:50 PM com.jme3.audio.openal.ALAudioRenderer initOpenAL
INFO: Audio effect extension version: 1.0
Jan 11, 2018 2:14:50 PM com.jme3.audio.openal.ALAudioRenderer initOpenAL
INFO: Audio max auxiliary sends: 4
Jan 11, 2018 2:14:53 PM com.jme3.system.lwjgl.LwjglDisplay runLoop
SEVERE: Failed to set display settings!
org.lwjgl.LWJGLException: Could not make context current
at org.lwjgl.opengl.WindowsContextImplementation.nMakeCurrent(Native Method)
at org.lwjgl.opengl.WindowsContextImplementation.makeCurrent(WindowsContextImplementation.java:94)
at org.lwjgl.opengl.ContextGL.makeCurrent(ContextGL.java:194)
at org.lwjgl.opengl.DrawableGL.makeCurrent(DrawableGL.java:110)
at org.lwjgl.opengl.Display.makeCurrent(Display.java:706)
at org.lwjgl.opengl.Display.makeCurrentAndSetSwapInterval(Display.java:1025)
at org.lwjgl.opengl.Display.setDisplayModeAndFullscreenInternal(Display.java:512)
at org.lwjgl.opengl.Display.setFullscreen(Display.java:475)
at com.jme3.system.lwjgl.LwjglDisplay.createContext(LwjglDisplay.java:119)
at com.jme3.system.lwjgl.LwjglDisplay.runLoop(LwjglDisplay.java:180)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:232)
at java.lang.Thread.run(Thread.java:745)
Jan 11, 2018 2:14:53 PM com.jme3.app.LegacyApplication handleError
SEVERE: Uncaught exception thrown in Thread[jME3 Main,5,main]
java.lang.IllegalStateException: Keyboard must be created before you can poll the device
at org.lwjgl.input.Keyboard.poll(Keyboard.java:386)
at com.jme3.input.lwjgl.LwjglKeyInput.update(LwjglKeyInput.java:79)
at com.jme3.input.InputManager.update(InputManager.java:896)
at com.jme3.app.LegacyApplication.update(LegacyApplication.java:725)
at com.jme3.app.SimpleApplication.update(SimpleApplication.java:227)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.runLoop(LwjglAbstractDisplay.java:151)
at com.jme3.system.lwjgl.LwjglDisplay.runLoop(LwjglDisplay.java:193)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:232)
at java.lang.Thread.run(Thread.java:745)
AL lib: (EE) alc_cleanup: 1 device not closed
Exception: java.lang.RuntimeException thrown from the UncaughtExceptionHandler in thread "jME3 Main"
Hi, I did the test with the code but I do not have this problem. The program continues to function without getting stuck. I'm using JME 3.2
If you haven't already, try launching in full-screen mode and then pressing the "P" key.
After further investigation, it seems that the exception isn't raised unless the initial display mode has a color depth of 16 bits per pixel. If the initial mode has a color depth of 32 bits per pixel, the switch to windowed mode goes smoothly.
This problem may be related to your issue:
https://github.com/jMonkeyEngine/jmonkeyengine/issues/801
Well the os is useing 32bit for framebuffers in the window manager, maybe it is an invalid call to create a window with 16bit (and lwjgl will do just that)?
This does seem connected to issue #801. But in 801, there's no exception raised.
Need to re-test with both LWJGL v2 and v3.
Still seeing this issue with LWJGL v2 but not with v3.
With my improved understanding of LWJGL, I suspect this issue is fixable.
I'm still seeing this issue with JME 3.6.0-stable (LWJGL v2.9.5).
I can not reproduce this. Tried with 3.6.0-stable. Works fine for me with both lwjgl2 and lwjgl3.
Edit:
it seems that the exception isn't raised unless the initial display mode has a color depth of 16 bits per pixel.
In my case the only available color depth is 24 bpp when fullscreen is selected.
Edit2:
I noticed if I change
void goWindowed() {
settings.setFullscreen(false);
setSettings(settings);
restart();
}
to
void goWindowed() {
settings.setFullscreen(false);
settings.setDepthBits(32);
setSettings(settings);
restart();
}
I get this exception when switching from full-screen:
Mar 21, 2023 3:46:02 PM com.jme3.system.JmeDesktopSystem initialize
INFO: Running on jMonkeyEngine 3.6.0-stable
* Branch: HEAD
* Git Hash: 53f2a49
* Build Date: 2023-03-20
Mar 21, 2023 3:46:02 PM com.jme3.system.lwjgl.LwjglContext printContextInitInfo
INFO: LWJGL 2.9.5 context running on thread jME3 Main
* Graphics Adapter: null
* Driver Version: null
* Scaling Factor: 1
Mar 21, 2023 3:46:02 PM com.jme3.renderer.opengl.GLRenderer loadCapabilitiesCommon
INFO: OpenGL Renderer Information
* Vendor: Intel Open Source Technology Center
* Renderer: Mesa DRI Intel(R) HD Graphics 3000 (SNB GT2)
* OpenGL Version: 3.3 (Core Profile) Mesa 20.0.8
* GLSL Version: 3.30
* Profile: Core
Mar 21, 2023 3:46:03 PM com.jme3.audio.openal.ALAudioRenderer initOpenAL
INFO: Audio Renderer Information
* Device: OpenAL Soft
* Vendor: OpenAL Community
* Renderer: OpenAL Soft
* Version: 1.1 ALSOFT 1.15.1
* Supported channels: 64
* ALC extensions: ALC_ENUMERATE_ALL_EXT ALC_ENUMERATION_EXT ALC_EXT_CAPTURE ALC_EXT_DEDICATED ALC_EXT_disconnect ALC_EXT_EFX ALC_EXT_thread_local_context ALC_SOFT_loopback
* AL extensions: AL_EXT_ALAW AL_EXT_DOUBLE AL_EXT_EXPONENT_DISTANCE AL_EXT_FLOAT32 AL_EXT_IMA4 AL_EXT_LINEAR_DISTANCE AL_EXT_MCFORMATS AL_EXT_MULAW AL_EXT_MULAW_MCFORMATS AL_EXT_OFFSET AL_EXT_source_distance_model AL_LOKI_quadriphonic AL_SOFT_buffer_samples AL_SOFT_buffer_sub_data AL_SOFTX_deferred_updates AL_SOFT_direct_channels AL_SOFT_loop_points AL_SOFT_source_latency
Mar 21, 2023 3:46:03 PM com.jme3.audio.openal.ALAudioRenderer initOpenAL
WARNING: Pausing audio device not supported.
Mar 21, 2023 3:46:03 PM com.jme3.audio.openal.ALAudioRenderer initOpenAL
INFO: Audio effect extension version: 1.0
Mar 21, 2023 3:46:03 PM com.jme3.audio.openal.ALAudioRenderer initOpenAL
INFO: Audio max auxiliary sends: 4
Mar 21, 2023 3:46:10 PM com.jme3.system.lwjgl.LwjglDisplay runLoop
SEVERE: Failed to set display settings!
org.lwjgl.LWJGLException: Could not choose GLX13 config
at org.lwjgl.opengl.LinuxDisplayPeerInfo.initDefaultPeerInfo(Native Method)
at org.lwjgl.opengl.LinuxDisplayPeerInfo.<init>(LinuxDisplayPeerInfo.java:61)
at org.lwjgl.opengl.LinuxDisplay.createPeerInfo(LinuxDisplay.java:827)
at org.lwjgl.opengl.DrawableGL.setPixelFormat(DrawableGL.java:61)
at org.lwjgl.opengl.Display.create(Display.java:846)
at org.lwjgl.opengl.Display.create(Display.java:797)
at com.jme3.system.lwjgl.LwjglDisplay.createContext(LwjglDisplay.java:161)
at com.jme3.system.lwjgl.LwjglDisplay.runLoop(LwjglDisplay.java:206)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:242)
at java.base/java.lang.Thread.run(Thread.java:1589)
Mar 21, 2023 3:46:10 PM com.jme3.app.LegacyApplication handleError
SEVERE: Uncaught exception thrown in Thread[#33,jME3 Main,5,main]
java.lang.RuntimeException: No OpenGL context found in the current thread.
at org.lwjgl.opengl.GLContext.getCapabilities(GLContext.java:124)
at com.jme3.system.lwjgl.LwjglContext.initContext(LwjglContext.java:285)
at com.jme3.system.lwjgl.LwjglContext.reinitContext(LwjglContext.java:267)
at com.jme3.system.lwjgl.LwjglDisplay.runLoop(LwjglDisplay.java:212)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:242)
at java.base/java.lang.Thread.run(Thread.java:1589)
and if I change it to
void goWindowed() {
settings.setFullscreen(false);
settings.setDepthBits(16);
setSettings(settings);
restart();
}
it shows a blank window after switching. (no spatial is rendered in the viewport)
Maybe changing color depth is not supported with context restart.
I made a commit to the master branch that may fix this issue, please re-test this from the master.
Feel free to reopen it if you still have the issue.
I reproduced the issue on Mint Linux using 3.6.0-stable. Then I ran the same test using jMonkeyEngine master branch at Git Hash 365759d and was unable to reproduce the issue. So I think it's solved.
Thank you, @Ali-RS!