Runtime Exception thrown when attempting setFullScreen(true) and setShowSettings(false)

Hi, I’m new and I’m playing around with the basic project, and I have the following problem. I would like to set the game’s full screen resolution myself depending on the the actual computer screen, without using a splash screen. So long as I have the splash screen display it seems to work fine, but when I turn off the splash screen using the setShowSettings(false) method I get a runtime exception from the LWJGL. Here’s my code as it stands and then the stack trace I’m getting:

public class Main extends SimpleApplication {
    private static Main applicationInstance = new Main();
    private static AppSettings configurationInstance = new AppSettings(true);
    public static void main(String[] args) {
        getLargestFullScreenResolutionAllowed();
        configurationInstance.setFullscreen(true);
        configurationInstance.setSamples(2);    // anti-aliasing
        configurationInstance.setTitle("Playing Around"); // branding: window name
        applicationInstance.setShowSettings(false);
        applicationInstance.setSettings(configurationInstance);
        applicationInstance.start();
    }
    private static void getLargestFullScreenResolutionAllowed() {
        GraphicsDevice device = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
        DisplayMode[] modes = device.getDisplayModes();
        DisplayMode largestMode = findLargestDisplayMode(modes);
        configurationInstance.setResolution(largestMode.getWidth(), largestMode.getHeight());
        configurationInstance.setBitsPerPixel(largestMode.getBitDepth());
        configurationInstance.setFrequency(largestMode.getRefreshRate());
    }
    private static DisplayMode findLargestDisplayMode(DisplayMode[] modes) {
        int lastModeArea = 0;
        DisplayMode lastBiggestMode = null;
        for (DisplayMode mode : modes) {
            int modeArea = mode.getHeight() * mode.getWidth();
            if (modeArea > lastModeArea) {
                lastBiggestMode = mode;
                lastModeArea = modeArea;
            }
        }
        if (lastBiggestMode == null) {
            return modes[0];
        }
        return lastBiggestMode;
    }
}

The stack trace for the Runtime Exception is such:

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:207)
at java.lang.Thread.run(Thread.java:744)

Aug 13, 2015 9:04:32 AM com.jme3.system.lwjgl.LwjglAbstractDisplay run
SEVERE: Display initialization failed. Cannot continue.

Basically I’m wondering why I the display fails initialization when there is no splash screen?

It seems I may have figured a work around in any case. Instead of reading the DisplayMode values from the GraphicsDevice I’m just putting in the integer values directly, I guess the question is do I really need to set the resolution if I’m going to be in full screen anyway?

[edit]
Apparently so, as it seems that if I don’t tell it what resolution it gives me some crappy small resolution that looks really distorted on my laptop :/. It would really be nice to read these values before the start of the application without the need of splash screen.

It’s not the splash screen that you’ve turned off… it’s the settings dialog… which sets up settings.

Indicates that you are setting the settings differently when you set them manually than the settings dialog sets. You could always re-enable it to see what it’s setting so that you can see what you’ve missed/set differently.

Thanks for the reply pspeed. I decided to start over fresh (so basically threw out my first project and started a new one) and I create the instance of the Main and the AppSettings inside the static main method and specifically add the resolution without trying to read it from the graphics device it seems to be working correctly without the use of the splash screen settings configuration. Of course the problem is that I would want that if I run this on a computer with a better resolution than my laptop I should be able to define that without a splash screen allowing me to chose this. So basically that’s where I am right now, trying to figure out how to get the screen’s width and height values at startup.

The problem is the bit depth you set.

The AppSettings from jMonkey requires a bit depth of 16 or 24 (see javadoc of AppSetting.setBitsPerPixel(…).

You query the DisplayModes. If you read the java docs of DisplayMode.getBitDepth(…) you see, that this method might deliver BIT_DEPTH_MULTI if multiple bit depths are allowed for this DisplayMode (e.g. 16 and 24 are allowed).And BIT_DEPTH_MULTI is a constant defined as -1.

So: you are trying to pass -1 to the AppSettings.setBitsPerPixel() which causes the error.

Workaround: set the desired bit depths manually, e.g

// configurationInstance.setBitsPerPixel(largestMode.getBitDepth());
configurationInstance.setBitsPerPixel(24);

or you just don’t set any bit depth and take the default bit depth that jMonkey suggests. In that case you really shoud instantiate the AppSettings with

private static AppSettings configurationInstance = new AppSettings(true);

as you already do. DO NOT USE false AS PARAMETER.

1 Like

Ah! That’s got it thanks. You’re right I should have looked at the possible values returned from DisplayMode.getBitDepth(…).

The source code for the app settings dialog is available if you ever want to see how it does things to resolve some future similar issue.

1 Like

If you set AppSettings fullscreen to true and width / height to -1, jME3 will use a fullscreen mode based on the current mode set on the desktop, so you don’t actually need to set those values.

1 Like