Weird resolution problem

Hi there,

I wrote a small active rendering loop that worked quite fast. But somehow I managed to get the thing broken and I have no idea what causes the trouble.

here’s the basic part of the loop:


    //Constructor
    public GameWindow(GraphicsDevice device, int userDefinedGameTicks) {

        gd = device;
        setUndecorated(true);
        if (gd.isFullScreenSupported()) {
            gd.setFullScreenWindow(this);
        } else {
            System.out.println("Fullscreen not supported");
            System.exit(0);
        }

        DisplayMode[] dmodes = gd.getDisplayModes();
        Config.readIni();
        if (gd.isDisplayChangeSupported()) {
            gd.setDisplayMode(dmodes[Config.getDm()]);
        } else {
            System.out.println("Displaymode not supported");
            System.exit(0);
        }
        
        //debug information
        System.out.println(getWidth());
        System.out.println(getHeight());

            createBufferStrategy(2);
            bs = this.getBufferStrategy();

        width = this.getWidth();
        height = this.getHeight();

        fTime = .00001;
        timer = new AdvancedTimer();
        gameticks_per_second = userDefinedGameTicks;
        gametick_time = timer.getTicksPerSecond() / gameticks_per_second;
        iLib.loadAllImages();
        timer.start();

        run();
    }

    public static void main(String[] args) {
        System.setProperty("sun.java2d.translaccel", "true");
        System.setProperty("sun.java2d.accthreshold", "0");
        System.setProperty("sun.java2d.ddscale", "true");
        System.setProperty("sun.java2d.ddforcevram", "true");

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

        new GameWindow(device, 20);
    }


The result is a white screen without any rendering. There’s this system-message:

“java.lang.IllegalArgumentException: Width (0) and height (600) cannot be <= 0”

So I checked the initial Desktop-Resolution (1600x1200) with a System.out… before I switch to the Loop-Resolution (which is bzw. 800x600)

And all I get is:
width: 0
height: 1200

really strange thing. any ideas??

I think a window / frame might give a zero width or height if they’re requested before it is shown.
THis is just a guess.
You could maybe try doing a pack() before calling getWidth()?

thx for the reply.

I tried pack() but it didnt help.

It seemes the problem occured first, when I unplugged my second monitor (if I remember correctly…some time ago). Now I am currently working with a laptop. Strange enough that similar applications run perfectly.

Even more strange thing is, that there’s always width = 0, but the height works correctly.

What java version are you using? I believe it was 5.0 when we made setDisplayMode synchronus.

Also, why not use display mode’s dimensions instead of component’s?

[quote]Also, why not use display mode’s dimensions instead of component’s?
[/quote]
That did it !! :wink:

a huge thanks to you !

(btw. I am using jre 1.5.0_01)