JME Application Micro Stutter/Freeze

Hello there!

I’ve been working on my game project using JME for a small while now, and JME has been fantastic. But recently I’ve bumped into a nuisance of an issue while running my app in windowed mode - every so often (anywhere from ~3s - 10s) there is a very noticeable “freeze” or “stutter” (sometimes it even looks like rubber-banding). It is far less noticeable/frequent in fullscreen mode.

I’m certain it’s not caused by my app logic, as I used this bare-bones test app where the issue is present:

import com.jme3.app.SimpleApplication;
import com.jme3.scene.Spatial;
import com.jme3.util.SkyFactory;

public class TestApp extends SimpleApplication {

    private Spatial SKYBOX;
    private final String SKYBOX_TEXTURE = "Textures/Sky/PurpleSpace.dds";
    private final SkyFactory.EnvMapType SKYBOX_TEXTURE_TYPE = SkyFactory.EnvMapType.CubeMap;

    @Override
    public void simpleInitApp() {
        
        SKYBOX = SkyFactory.createSky(assetManager, SKYBOX_TEXTURE, SKYBOX_TEXTURE_TYPE);
        rootNode.attachChild(SKYBOX);

        var previewModel = assetManager.loadModel("Models/BoomBox.j3o");
        previewModel.scale(100);
        rootNode.attachChild(previewModel);
    }


    @Override
    public void simpleUpdate(float tpf) {
    }
}

I’ve conducted a bit of research, but haven’t found anything helpful - other than that it is perhaps a Windows/OpenGL-related issue?

If anyone could help me out with this issue, I’d greatly appreciate it! :pray:

How is that simple application being started with no main method?

You are turning on vsync, yes?

…then just flying around and feeling occasional lag?

Which Windows? Which GPU? etc.

Edit: also are you starting the app from the SDK or from the command line?

Edit2: (for what it’s worth I do not experience this problem)

Hey Paul!

  • I have vsync on (though I tried it with it off and the same issue persists).
  • I am indeed flying around and feeling the lag, and it happens every some odd seconds.
  • Windows version: Windows 11 Version 10.0.22631 Build 22631
  • GPU: RTX 3070 mobile, and an integrated Iris(R) Xe
  • I have the code loaded as a gradle project into Intellij, so I am running the main method through Intellij
  • JME sdk 3.6.1-stable

Sorry about the code snippet - this is actually the main method that’s firing off the simple application (I had pulled the code into its own app and ran it from the main method elsewhere).

Amended code:

package com.mygame;

import com.jme3.app.SimpleApplication;
import com.jme3.light.LightProbe;
import com.jme3.math.Vector3f;
import com.jme3.renderer.RenderManager;

import com.jme3.scene.Spatial;
import com.jme3.system.AppSettings;
import com.jme3.util.SkyFactory;

public class Main extends SimpleApplication {

    private Spatial SKYBOX;
    private final String SKYBOX_TEXTURE = "Textures/Sky/PurpleSpace.dds";
    private final SkyFactory.EnvMapType SKYBOX_TEXTURE_TYPE = SkyFactory.EnvMapType.CubeMap;

    public static void main(String[] args) {
        Main app = new Main();
        app.start();
    }

    @Override
    public void simpleInitApp() {
        SKYBOX = SkyFactory.createSky(assetManager, SKYBOX_TEXTURE, SKYBOX_TEXTURE_TYPE);
        rootNode.attachChild(SKYBOX);

        var previewModel = assetManager.loadModel("Models/BoomBox.j3o");
        previewModel.scale(100);
        rootNode.attachChild(previewModel);

        // load ibl
        Spatial probeHolder = getAssetManager().loadModel("abc.j3o");
        LightProbe probe = (LightProbe) probeHolder.getLocalLightList().get(0);
        probe.setPosition(Vector3f.ZERO);
        probe.getArea().setRadius(1000f);
        probeHolder.removeLight(probe);
        getRootNode().addLight(probe);
    }

    @Override
    public void simpleUpdate(float tpf) {
    }

    public AppSettings getSettings() {
        return settings;
    }

    @Override
    public void simpleRender(RenderManager rm) {
    }
}

Try using gradle run or whatever to run it outside of the IDE just to rule that out.

Just ran it with ./gradlew run, and it appears the same issue is present, unfortunately.

I guess you can just sample it then. See if there is some fishy going on. Like GC or some code (although this might not be your code then…). With jVisualVM for example.

And post the log output, just to make sure it is not running on the integrated gpu.

@zzuegg Are you referring to the console log/output? This is the output of the app execution when I run ./gradlew run:

Yeah. So it runs on the rtx. One thing ruled out.

@tonihele VisualVM’s sampler options gives me cpu/memory, and I got this output:

Only thing that seems fishy to me is maybe(?) the high CPU time for glfwSwapBuffers and JNI.invokePV, but I’ve also heard that it’s probably normal, at least in this case since nothing is going on in the application…

In terms of memory allocations, jME3 Main occupies 5% of the heap dump, with the rest being RMI TCP which is just the connection to the VisualVM feed.

You can also see that do the GC match your stutter occasions. There are different GCs available to try if that is the issue. I haven’t seen this on my own projects ever, the default GC is pretty good.

I don’t run Windows 11… but why am I feeling like I have a vague memory of some article talking about getting games to run properly on Windows 11. (Not JME games but games in general…) Like, it keeps them from running at max performance or something.

Trying to google “windows 11 game performance issues” comes up with so many hits I don’t even know how to sort them. First one:
https://answers.microsoft.com/en-us/windows/forum/all/windows-11-updates-made-all-my-games-stutter-and/70ce15d2-97e7-4cb4-a597-8b577b8f612c

…do other games exhibit similar behavior by any chance?

Running other Java or OpenGL games? (Like, if you have Java minecraft or download Mythruna or something.)

@pspeed @tonihele Thanks for the tips, I’ll head in that direction next.

I also made a quick gif from my phone recording of my monitor capturing the issue here screen capture gif. At the beginning and the end, there is a bit of lag/rubber-banding. In this .gif I’m moving the camera to the left and strafing past the 3d model.

I might also be reaching a bit, but is there any chance I need to configure something for my application, if my laptop is hooked up to a monitor and using the monitor screen exclusively (display settings set to show only on the monitor)? I messed around a bit and ran my application on an older computer (hooked up to the same monitor) and got the same issue to occur. But if I don’t use a monitor and only use the laptop’s native screen, the issue doesn’t occur for either of my computers (or is just so subtle I don’t notice it).

Hello @StellarTek and welcome.

I have a few questions since it happened to me before. I have a AMD graphics card and my monitor that is FreeSync compatible.

  • Did you install the monitor’s drivers? Windows default monitor drivers just allows 60Hz only and have poor latency. The drivers unlock what your monitor can do.
  • Is your Monitor GSync compatible?
  • Check your monitor cable (hdmi/display port) if it supports what your monitor can do.

I hope this helps

1 Like

Try turning off “Threaded Optimization” in your NVIDIA card settings. Years ago, I had a similar problem with my game, and NVIDIA was trying to do something fancy with threading that caused weird blocks with OpenGL.

2 Likes

@glh3586 I’ll give that a try, thank you.

@bloodwalker I haven’t installed any monitor drivers, have been using it out-of-the-box. Nice to know that - I’ll dig around for some drivers. Doesn’t appear to be Gsync, but is Adaptive Sync (unless that’s the same thing).