Error: Can't launch jME3 projects in fullscreen

Hey guys, so after a long break, I decided to work on my jME projects again. I hadn’t touched my current project since I changed to Ubuntu, so I was surprised that, when i tried to launch in full screen, it gave me the following error:

SEVERE: Failed to create display
java.lang.RuntimeException: Unable to find fullscreen display mode matching settings
	at com.jme3.system.lwjgl.LwjglDisplay.createContext(LwjglDisplay.java:79)
	at com.jme3.system.lwjgl.LwjglAbstractDisplay.initInThread(LwjglAbstractDisplay.java:113)
	at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:211)
	at java.lang.Thread.run(Thread.java:745)

nov 11, 2017 6:47:53 PM com.jme3.system.lwjgl.LwjglAbstractDisplay run
SEVERE: Display initialization failed. Cannot continue.

Hoping that this error was due to my incredibly dirty code, I tried to create a new project (the default one with the blue cube), but it still gave me that error.

I did realize it was giving me a weird resolution option: 3046x1050. I soon realized that was the resolution of my two monitors combined, so I decided to turn off one of them and see if it would work. It didn’t. (Although the maximum resolution i could pick this time was 1366x768, which is the resolution of the primary monitor.

I also tried picking other lower resolutions, to no avail.

Has anyone experienced this error? I’m using Ubuntu 16.04, jMonkey 3.1 stable and my graphics card’s drivers are updated.

What mode is your desktop? Because maybe its right. You cant have that res when your desktop (both monitors) dont support that resolution when combined. Do you have that issue when they are in a seperate mode? A.k.a. switched on but not combined. Or setting a resolution they support combined?

I didn’t understand that question. However I did try unpluging the external monitor (and running xrandr to update the change) and tried to run this time. It did fix that odd resolution number (the max now was only 1366x768), but it still gave the exact same error.

Try 2732x768. Its trying to set both monitors to an unsupported res and failed. Im not sure how to override the desktop behavior like that.

1 Like

Will try then, I think I can manually set the resolution throught the AppSettings.

Im saying there should be a way to specify a monitor and use just that one. Im not certain how, though. Appsettings does have the beginnings.

Tried this:

        AppSettings defs = new AppSettings(true);
        defs.setFullscreen(true);
        defs.setWidth(2732);
        defs.setHeight(768);
        
        Main app = new Main();
        app.setShowSettings(false);
        app.setSettings(defs);
        app.start();
    }

Still now working. Exact same error…

Here is where it initializes everything. It has at least a list of supported displaymodes you may want to peek at.

I found this at the file you gave me:

GraphicsDevice device = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();

modes = device.getDisplayModes();

I decided to try this:

        GraphicsDevice gd = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
        for(DisplayMode mode : gd.getDisplayModes()) {
            System.out.println(mode.getWidth() + " * " + mode.getHeight());
        }

And it outputs this:

1366 * 768
1366 * 768
1280 * 720
1024 * 768
800 * 600
640 * 480

Does this help on something?

you can use fullscreen mode only with native screen resolution in the case with LWJGL3.

OK, after debugging the code, I found the root of the problem: refresh rate.

Here’s the code that was throwing that exception:

LwjglDisplay.java

protected void createContext(AppSettings settings) throws LWJGLException{
        DisplayMode displayMode;
        if (settings.getWidth() <= 0 || settings.getHeight() <= 0){
            displayMode = Display.getDesktopDisplayMode();
            settings.setResolution(displayMode.getWidth(), displayMode.getHeight());
        }else if (settings.isFullscreen()){
            displayMode = getFullscreenDisplayMode(settings.getWidth(), settings.getHeight(),
                                                   settings.getBitsPerPixel(), settings.getFrequency());
            if (displayMode == null) {
                throw new RuntimeException("Unable to find fullscreen display mode matching settings");
            }
        }else{
            displayMode = new DisplayMode(settings.getWidth(), settings.getHeight());
        }

And here’s the getFullscreenDisplayMode:

    protected DisplayMode getFullscreenDisplayMode(int width, int height, int bpp, int freq){
        try {
            DisplayMode[] modes = Display.getAvailableDisplayModes();
            for (DisplayMode mode : modes) {
                if (mode.getWidth() == width
                        && mode.getHeight() == height
                        && (mode.getBitsPerPixel() == bpp || (bpp == 24 && mode.getBitsPerPixel() == 32))
                        && (mode.getFrequency() == freq || (freq == 60 && mode.getFrequency() == 59))) {
                    return mode;
                }
            }
        } catch (LWJGLException ex) {
            listener.handleError("Failed to acquire fullscreen display mode!", ex);
        }

After seeing this if testing for 4 conditions, I knew one of them was failing.

And when I run the game with the settings dialog, the refresh rate is set to this:

This is a really odd number for a refresh rate. Looking at the value NVIDIA X Server Settings gives me, my main screen is 60,03Hz and the second screen is 59,95Hz.

Now I know the culprit here is the 51Hz option jMonkey forces me to choose. If I instead hard-code my settings like this:

        AppSettings defs = new AppSettings(true);
        defs.setFullscreen(true);
        defs.setWidth(1366);
        defs.setHeight(768);
        defs.setFrequency(60);
        
        Main app = new Main();
        app.setShowSettings(false);
        app.setSettings(defs);
        app.start();

The game now runs in fullscreen mode.

So, what’s left to know now is, why is jMonkey giving me that weird refresh rate value?

1 Like

After more debugging, I found out the AppSettings are being given the correct refresh rate value of 60Hz. However, when jMonkey loads the settings saved from registry, it changes the frequency value to 51Hz. So the culprit must be the settings saved in the registry.

How can I delete those saved (and probably corrupted) settings?

1 Like

On Linux there is no registry. Its a Folder in ~ (User home) starting with a dot (.jmonkeyengine?)

Good find! I’d expect awt to return those faulty rates

Edit: I found it in ~/.java/.userPrefs/, so just xdg-open ~/.java/.userPrefs to inspect

Edit: My Files show the following (no refresh rate specified, yet it recommends these 51Hz when I toggle fullscreen).

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE map SYSTEM "http://java.sun.com/dtd/preferences.dtd">
<map MAP_XML_VERSION="1.0">
  <entry key="B_DisableJoysticks" value="false"/>
  <entry key="B_Fullscreen" value="false"/>
  <entry key="B_GammaCorrection" value="false"/>
  <entry key="B_OpenCL" value="false"/>
  <entry key="B_Resizable" value="false"/>
  <entry key="B_SwapBuffers" value="true"/>
  <entry key="B_UseInput" value="true"/>
  <entry key="B_VSync" value="true"/>
  <entry key="I_BitsPerPixel" value="24"/>
  <entry key="I_DepthBits" value="24"/>
  <entry key="I_FrameRate" value="-1"/>
  <entry key="I_Frequency" value="-1"/>
  <entry key="I_Height" value="720"/>
  <entry key="I_MinHeight" value="0"/>
  <entry key="I_MinWidth" value="0"/>
  <entry key="I_Samples" value="0"/>
  <entry key="I_StencilBits" value="0"/>
  <entry key="I_Width" value="1280"/>
  <entry key="S_AudioRenderer" value="LWJGL"/>
  <entry key="S_OpenCLPlatformChooser" value="com.jme3.opencl.DefaultPlatformChooser"/>
  <entry key="S_Renderer" value="LWJGL-OpenGL2"/>
  <entry key="S_SettingsDialogImage" value="/com/jme3/app/Monkey.png"/>
  <entry key="S_Title" value="MyTitle"/>
</map>

Thanks! I tried to delete the file (which was inside a folder with a weird name, something like “!):7ef@/”), rerun the game aaand:

It still showed up the refresh rate as 51Hz.

So, after more “digging”, here’s what I found out:

AWT is the thing giving weird refresh rates. DisplayMode from LWJGL return 60Hz (as expected), however, by writing a quick debug code:

        for(DisplayMode mode : gd.getDisplayModes()) {
            System.out.println(mode.getWidth() + " * " + mode.getHeight());
            System.out.println("Refresh rate: " + mode.getRefreshRate());
        }

It return this:

3046 * 1050
Refresh rate: 50
1366 * 768
Refresh rate: 51
1280 * 720
Refresh rate: 52
1024 * 768
Refresh rate: 53
800 * 600
Refresh rate: 54
640 * 480
Refresh rate: 55

So, I assume this is a problem with AWT itself and not related to jMonkey.
But, why? Did a quick google search to see if others were having a similar problem, but couldn’t find anything useful…

If someone out there runs Ubuntu 16.04 (or any distribution of Linux), can you please try this simple test case and report what is returned? (I’m going to ask to a friend of mine who runs Arch Linux and see if he has the same problems)

public static void main(String[] args) {
    GraphicsDevice gd = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
    for(DisplayMode mode : gd.getDisplayModes()) {
        System.out.println(mode.getWidth() + " * " + mode.getHeight());
        System.out.println("Refresh rate: " + mode.getRefreshRate());
    }
}

Hint: it might also be solved with openjdk or java 9 (just like lwjgl3 has a problem with awt since java 8)

After asking my friend to test on his system (running Arch Linux), here’s the results:

1366 * 768
Refresh rate: 60
1024 * 768
Refresh rate: 60
1024 * 576
Refresh rate: 60
960 * 540
Refresh rate: 60
800 * 600
Refresh rate: 60
800 * 600
Refresh rate: 56
864 * 486
Refresh rate: 60
640 * 480
Refresh rate: 60
720 * 405
Refresh rate: 60
680 * 384
Refresh rate: 60
640 * 360
Refresh rate: 60

So, maybe this problem only happens on Ubuntu???

Lets find out the used drivers, gpus, x11/wayland and windowmanagers

In my case Nvidia proprietary GTX 1060 on x11 sddm/KDE Plasma in a Multi Display setup

And while it could be, it might also be that Arch just has more recent software. What Java Version did he Test it on? Java 8 (as in Not 9)