[SOLVED] Application.restart() with LWJGL v3

Is anyone besides me using JME’s Application.restart() method with LWJGL v3 (jme3-lwjgl3)?

Today I discovered an issue in my Acorus project, where pressing the Enter key invokes restart() and blanks the application window. The app continues running with a blank gray window; there’s no stack trace. However, the window isn’t supposed to go blank!

Here’s the relevant code in my project:

If I comment out line 160, the window displays normally after I press Enter, but of course the new settings don’t get applied either.

I’m puzzled why I didn’t notice this issue sooner. I’m pretty sure the applyToContext() feature worked last year.

At first I suspected it was a regression related to JME v3.8.0-alpha1, but then I found the issue occurs also with JME v3.6.1-stable.

LWJGL v2 (jme3-lwjgl) doesn’t seem to have this issue.

For forestall what a lot of folks will presumably immediately think at first…

Presumably, proposedSettings are settings that would otherwise work ok.

1 Like

Good point. I added code to dump clone before the restart(), and here are its entries:

{DepthBits=24, 
WindowWidth=-2147483648, 
MinHeight=0, 
DisableJoysticks=true, 
SwapBuffers=true, 
Resizable=true, 
CenterWindow=true, 
Height=500, 
BitsPerPixel=24, 
Width=746, 
UseRetinaFrameBuffer=false, 
UseInput=true, 
FrameRate=-1, 
Title=TestDsEdit , 
GammaCorrection=true, 
AudioRenderer=null, 
WindowXPosition=0, 
WindowHeight=-2147483648, 
WindowYPosition=0, 
MinWidth=0, 
VSync=false, 
Samples=1, 
StencilBits=0, 
SettingsDialogImage=/com/jme3/app/Monkey.png, 
Renderer=LWJGL-OpenGL3,
OpenCLPlatformChooser=com.jme3.opencl.DefaultPlatformChooser, 
Frequency=60, 
Fullscreen=false, 
OpenCL=false}

WindowWidth and WindowHeight look problematic. I am investigating.

EDIT: negative values for “WindowWidth” and “WindowHeight” are valid. They indicate to create the window using the width and height of the primary monitor’s current mode.

The glfwCreateWindow call has to be made on the primary thread. Unfortunately it does not always generate an error if that is not the case.

1 Like

Do you know an easy way to test whether the current thread is the primary one?

mhm. as far i can see jme should handle that since the restart is executed in the update loop.

1 Like
package example;

import com.jme3.app.SimpleApplication;
import com.jme3.system.AppSettings;

public class MonkeyTest extends SimpleApplication {
    @Override
    public void simpleInitApp() {

    }

    float time=0;

    @Override
    public void simpleUpdate(float tpf) {
        super.simpleUpdate(tpf);
        time+=tpf;
        if(time>10){
            time=0;
            AppSettings appSettings = new AppSettings(true);
            setSettings(appSettings);
            restart();
        }
    }

    public static void main(String[] args) {
        AppSettings settings = new AppSettings(true);
        settings.setVSync(false);
        MonkeyTest monkeyTest = new MonkeyTest();
        monkeyTest.setSettings(settings);
        monkeyTest.start();
    }
}

this code works on my machine

1 Like

Mine too.

Correction: your test application doesn’t crash, but the render statistics vanish after 10 seconds, which I think is the same bug I’m seeing in Acorus.

Using printlns, I convinced myself that the thread executing restart() (“jME3 Main”) isn’t the same thread that executed start() (“main”):

Jan 02, 2025 9:09:04 PM com.jme3.system.JmeSystemDelegate lambda$new$1
WARNING: JmeDialogsFactory implementation not found.
Jan 02, 2025 9:09:04 PM com.jme3.system.JmeDesktopSystem initialize
INFO: Running on jMonkeyEngine 3.7.0-stable
 * Branch: HEAD
 * Git Hash: bc6cdf5
 * Build Date: 2024-10-21
start thread: main
Jan 02, 2025 9:09:05 PM com.jme3.system.lwjgl.LwjglContext printContextInitInfo
INFO: LWJGL 3.3.3+5 context running on thread jME3 Main
 * Graphics Adapter: GLFW 3.4.0 Wayland X11 GLX Null EGL OSMesa monotonic shared
Jan 02, 2025 9:09:05 PM com.jme3.renderer.opengl.GLRenderer loadCapabilitiesCommon
INFO: OpenGL Renderer Information
 * Vendor: NVIDIA Corporation
 * Renderer: NVIDIA GeForce RTX 2070/PCIe/SSE2
 * OpenGL Version: 3.2.0 NVIDIA 550.120
 * GLSL Version: 1.50 NVIDIA via Cg compiler
 * Profile: Core
Jan 02, 2025 9:09:05 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.23.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_device_clock ALC_SOFT_HRTF ALC_SOFT_loopback ALC_SOFT_loopback_bformat ALC_SOFT_output_limiter ALC_SOFT_output_mode ALC_SOFT_pause_device ALC_SOFT_reopen_device
 * AL extensions: AL_EXT_ALAW AL_EXT_BFORMAT 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_BFORMAT AL_EXT_MULAW_MCFORMATS AL_EXT_OFFSET AL_EXT_source_distance_model AL_EXT_SOURCE_RADIUS AL_EXT_STATIC_BUFFER AL_EXT_STEREO_ANGLES AL_LOKI_quadriphonic AL_SOFT_bformat_ex AL_SOFTX_bformat_hoa AL_SOFT_block_alignment AL_SOFT_buffer_length_query AL_SOFT_callback_buffer AL_SOFTX_convolution_reverb AL_SOFT_deferred_updates AL_SOFT_direct_channels AL_SOFT_direct_channels_remix AL_SOFT_effect_target AL_SOFT_events AL_SOFT_gain_clamp_ex AL_SOFTX_hold_on_disconnect AL_SOFT_loop_points AL_SOFTX_map_buffer AL_SOFT_MSADPCM AL_SOFT_source_latency AL_SOFT_source_length AL_SOFT_source_resampler AL_SOFT_source_spatialize AL_SOFT_source_start_delay AL_SOFT_UHJ AL_SOFT_UHJ_ex
Jan 02, 2025 9:09:05 PM com.jme3.audio.openal.ALAudioRenderer initOpenAL
INFO: Audio effect extension version: 1.0
Jan 02, 2025 9:09:05 PM com.jme3.audio.openal.ALAudioRenderer initOpenAL
INFO: Audio max auxiliary sends: 2
restart thread: jME3 Main
Jan 02, 2025 9:09:15 PM com.jme3.renderer.opengl.GLRenderer loadCapabilitiesCommon
INFO: OpenGL Renderer Information
 * Vendor: NVIDIA Corporation
 * Renderer: NVIDIA GeForce RTX 2070/PCIe/SSE2
 * OpenGL Version: 3.2.0 NVIDIA 550.120
 * GLSL Version: 1.50 NVIDIA via Cg compiler
 * Profile: Core

@zzuegg Do the render statistics vanish on your machine?

Yeah, everything renders correct on my side:

Jan 03, 2025 7:13:20 AM com.jme3.system.JmeSystemDelegate lambda$new$1
WARNING: JmeDialogsFactory implementation not found.
Jan 03, 2025 7:13:20 AM com.jme3.system.JmeDesktopSystem initialize
INFO: Running on jMonkeyEngine 3.6.0-stable
 * Branch: HEAD
 * Git Hash: 53f2a49
 * Build Date: 2023-03-20
[LWJGL] [ThreadLocalUtil] Unsupported JNI version detected, this may result in a crash. Please inform LWJGL developers.
Jan 03, 2025 7:13:20 AM com.jme3.system.lwjgl.LwjglContext printContextInitInfo
INFO: LWJGL 3.3.1 build 7 context running on thread jME3 Main
 * Graphics Adapter: GLFW 3.4.0 Win32 WGL Null EGL OSMesa VisualC DLL
Jan 03, 2025 7:13:21 AM com.jme3.renderer.opengl.GLRenderer loadCapabilitiesCommon
INFO: OpenGL Renderer Information
 * Vendor: NVIDIA Corporation
 * Renderer: NVIDIA GeForce GTX 1080 Ti/PCIe/SSE2
 * OpenGL Version: 3.2.0 NVIDIA 566.36
 * GLSL Version: 1.50 NVIDIA via Cg compiler
 * Profile: Core
Jan 03, 2025 7:13:21 AM com.jme3.audio.openal.ALAudioRenderer initOpenAL
INFO: Audio Renderer Information
 * Device: OpenAL Soft
 * Vendor: OpenAL Community
 * Renderer: OpenAL Soft
 * Version: 1.1 ALSOFT 1.21.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_device_clock ALC_SOFT_HRTF ALC_SOFT_loopback ALC_SOFT_loopback_bformat ALC_SOFT_output_limiter ALC_SOFT_pause_device
 * AL extensions: AL_EXT_ALAW AL_EXT_BFORMAT 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_BFORMAT AL_EXT_MULAW_MCFORMATS AL_EXT_OFFSET AL_EXT_source_distance_model AL_EXT_SOURCE_RADIUS AL_EXT_STEREO_ANGLES AL_LOKI_quadriphonic AL_SOFT_bformat_ex AL_SOFTX_bformat_hoa AL_SOFT_block_alignment AL_SOFTX_callback_buffer AL_SOFTX_convolution_reverb AL_SOFT_deferred_updates AL_SOFT_direct_channels AL_SOFT_direct_channels_remix AL_SOFT_effect_target AL_SOFT_events AL_SOFTX_filter_gain_ex AL_SOFT_gain_clamp_ex AL_SOFT_loop_points AL_SOFTX_map_buffer AL_SOFT_MSADPCM AL_SOFT_source_latency AL_SOFT_source_length AL_SOFT_source_resampler AL_SOFT_source_spatialize
Jan 03, 2025 7:13:21 AM com.jme3.audio.openal.ALAudioRenderer initOpenAL
INFO: Audio effect extension version: 1.0
Jan 03, 2025 7:13:21 AM com.jme3.audio.openal.ALAudioRenderer initOpenAL
INFO: Audio max auxiliary sends: 2
Jan 03, 2025 7:13:24 AM com.jme3.renderer.opengl.GLRenderer loadCapabilitiesCommon
INFO: OpenGL Renderer Information
 * Vendor: NVIDIA Corporation
 * Renderer: NVIDIA GeForce GTX 1080 Ti/PCIe/SSE2
 * OpenGL Version: 3.2.0 NVIDIA 566.36
 * GLSL Version: 1.50 NVIDIA via Cg compiler
 * Profile: Core
Jan 03, 2025 7:13:27 AM com.jme3.renderer.opengl.GLRenderer loadCapabilitiesCommon
INFO: OpenGL Renderer Information
 * Vendor: NVIDIA Corporation
 * Renderer: NVIDIA GeForce GTX 1080 Ti/PCIe/SSE2
 * OpenGL Version: 3.2.0 NVIDIA 566.36
 * GLSL Version: 1.50 NVIDIA via Cg compiler
 * Profile: Core

Jme does rename the thread in the context creation code.

Osx gets is special threatment, maybe linux/wayland requires a bit extra love too. Could it be that you changed os/windowmanager since the last time you remember it working?

1 Like

Story old as time :smiley: Nifty GUI doesn't display correctly after context restart · Issue #1013 · jMonkeyEngine/jmonkeyengine · GitHub. Although marked as Nifty bug, other parts of jME also suffer.

1 Like

With the additional hint that if windowWidth or windowHeight == Integer.MinValue then width or height is used. very confusing

Jme does rename the thread in the context creation code.

I don’t think the thread gets renamed on my machine; I think Application.start() creates a new thread. To verify this, I printed the thread IDs in main() and simpleUpdate(), and they’re different.

Examining the code, I think thread renaming occurs only on MacOS:

Different hardware and different Linux releases, perhaps, but surely still using Cinnamon/X11/Linux.

I hacked LjwglWindow.java to reuse the primary thread in create(), even on Linux. Even with restart() invoked on the primary thread, the render stats still disappear after 10 seconds. So I don’t think it’s a threading issue.

I re-tested Acorus on the same hardware running JME 3.8.0-alpha1/Windows 11, and restart() didn’t blank the window there. (It did, however cause the window to jump back to the primary monitor.) JME 3.6.1-stable gave similar results.

This suggests my issue might be Linux-specific. @zzuegg have you been testing on Windows?

Yeah i am running windows. I have currently no access to another OS so i cannot test anything.

Can you move the blanked out window? if yes the new window gets created successfully and glfwPollEvents() does it’s job.

1 Like

Yes, I can move the blank window using the mouse.

1 Like

can you try to resize the window and maybe log if the changes are passed to jme?

1 Like

After the window was blanked, resizing it caused SceneProcessor.reshape() to be invoked.

Hi, I remember discussing this here: SceneProcessor reshape() not called in 3.7.0-beta1.2 - #9 by xuan

I cannot reproduce it with my laptop (intel graphics and linux+x11).
I tried zzuegg’s example and the text doesn’t disappear after restarting, all looks fine.
Could it be only a problem with Nvidia drivers? what about AMD?

Jan 04, 2025 2:07:53 AM com.jme3.system.JmeSystemDelegate lambda$new$1
WARNING: JmeDialogsFactory implementation not found.
Jan 04, 2025 2:07:53 AM com.jme3.system.JmeDesktopSystem initialize
INFO: Running on jMonkeyEngine 3.7.0-stable
 * Branch: HEAD
 * Git Hash: bc6cdf5
 * Build Date: 2024-10-21
Jan 04, 2025 2:07:53 AM com.jme3.system.lwjgl.LwjglContext printContextInitInfo
INFO: LWJGL 3.3.3+5 context running on thread jME3 Main
 * Graphics Adapter: GLFW 3.4.0 Wayland X11 GLX Null EGL OSMesa monotonic shared
Jan 04, 2025 2:07:53 AM com.jme3.renderer.opengl.GLRenderer loadCapabilitiesCommon
INFO: OpenGL Renderer Information
 * Vendor: Intel
 * Renderer: Mesa Intel(R) UHD Graphics 620 (WHL GT2)
 * OpenGL Version: 4.6 (Core Profile) Mesa 20.3.5
 * GLSL Version: 4.60
 * Profile: Core
Jan 04, 2025 2:07:53 AM com.jme3.asset.AssetConfig loadText
WARNING: Cannot find loader com.jme3.scene.plugins.ogre.MeshLoader
Jan 04, 2025 2:07:53 AM com.jme3.asset.AssetConfig loadText
WARNING: Cannot find loader com.jme3.scene.plugins.ogre.SkeletonLoader
Jan 04, 2025 2:07:53 AM com.jme3.asset.AssetConfig loadText
WARNING: Cannot find loader com.jme3.scene.plugins.ogre.MaterialLoader
Jan 04, 2025 2:07:53 AM com.jme3.asset.AssetConfig loadText
WARNING: Cannot find loader com.jme3.scene.plugins.ogre.SceneLoader
Jan 04, 2025 2:07:53 AM com.jme3.asset.AssetConfig loadText
WARNING: Cannot find loader com.jme3.scene.plugins.fbx.FbxLoader
Jan 04, 2025 2:07:53 AM com.jme3.asset.AssetConfig loadText
WARNING: Cannot find loader com.jme3.scene.plugins.gltf.GltfLoader
Jan 04, 2025 2:07:53 AM com.jme3.asset.AssetConfig loadText
WARNING: Cannot find loader com.jme3.scene.plugins.gltf.BinLoader
Jan 04, 2025 2:07:53 AM com.jme3.asset.AssetConfig loadText
WARNING: Cannot find loader com.jme3.scene.plugins.gltf.GlbLoader
Jan 04, 2025 2:07:53 AM com.jme3.asset.AssetConfig loadText
WARNING: Cannot find loader com.jme3.audio.plugins.OGGLoader
Jan 04, 2025 2:07:53 AM com.jme3.audio.openal.ALAudioRenderer initOpenAL
INFO: Audio Renderer Information
 * Device: OpenAL Soft
 * Vendor: OpenAL Community
 * Renderer: OpenAL Soft
 * Version: 1.1 ALSOFT 1.23.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_device_clock ALC_SOFT_HRTF ALC_SOFT_loopback ALC_SOFT_loopback_bformat ALC_SOFT_output_limiter ALC_SOFT_output_mode ALC_SOFT_pause_device ALC_SOFT_reopen_device
 * AL extensions: AL_EXT_ALAW AL_EXT_BFORMAT 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_BFORMAT AL_EXT_MULAW_MCFORMATS AL_EXT_OFFSET AL_EXT_source_distance_model AL_EXT_SOURCE_RADIUS AL_EXT_STATIC_BUFFER AL_EXT_STEREO_ANGLES AL_LOKI_quadriphonic AL_SOFT_bformat_ex AL_SOFTX_bformat_hoa AL_SOFT_block_alignment AL_SOFT_buffer_length_query AL_SOFT_callback_buffer AL_SOFTX_convolution_reverb AL_SOFT_deferred_updates AL_SOFT_direct_channels AL_SOFT_direct_channels_remix AL_SOFT_effect_target AL_SOFT_events AL_SOFT_gain_clamp_ex AL_SOFTX_hold_on_disconnect AL_SOFT_loop_points AL_SOFTX_map_buffer AL_SOFT_MSADPCM AL_SOFT_source_latency AL_SOFT_source_length AL_SOFT_source_resampler AL_SOFT_source_spatialize AL_SOFT_source_start_delay AL_SOFT_UHJ AL_SOFT_UHJ_ex
Jan 04, 2025 2:07:53 AM com.jme3.audio.openal.ALAudioRenderer initOpenAL
INFO: Audio effect extension version: 1.0
Jan 04, 2025 2:07:53 AM com.jme3.audio.openal.ALAudioRenderer initOpenAL
INFO: Audio max auxiliary sends: 2
Jan 04, 2025 2:08:04 AM com.jme3.renderer.opengl.GLRenderer loadCapabilitiesCommon
INFO: OpenGL Renderer Information
 * Vendor: Intel
 * Renderer: Mesa Intel(R) UHD Graphics 620 (WHL GT2)
 * OpenGL Version: 4.6 (Core Profile) Mesa 20.3.5
 * GLSL Version: 4.60
 * Profile: Core
Jan 04, 2025 2:08:14 AM com.jme3.renderer.opengl.GLRenderer loadCapabilitiesCommon
INFO: OpenGL Renderer Information
 * Vendor: Intel
 * Renderer: Mesa Intel(R) UHD Graphics 620 (WHL GT2)
 * OpenGL Version: 4.6 (Core Profile) Mesa 20.3.5
 * GLSL Version: 4.60
 * Profile: Core

2 Likes