sync and sync2

Hands up who could see this coming :slight_smile:

After being advised to use the sync and sync2 methods rather than rely on vsync, I thought I’d try and test them out. Not sure if I’m doing this right but here’s how I’m using the method, using the mainloop from FullScreenWindowedTest as an example.

       private void mainLoop()
      {
            while (!Keyboard.isKeyDown(Keyboard.KEY_ESCAPE) && !Display.isCloseRequested())
            {
                  if (Display.isVisible())
                  {
                        // check keyboard input
                        processKeyboard();
                        // do "game" logic, and render it
                        logic();
                        render();
                  }
                  else
                  {
                        // no need to render/paint if nothing has changed (ie. window
                        // dragged over)
                        if (Display.isDirty())
                        {
                              render();
                        }
                        // don't waste cpu time, sleep more
                        try
                        {
                              Thread.sleep(100);
                        }
                        catch (InterruptedException inte)
                        {
                        }
                  }
                  // Update window
                  Display.sync(60); 
                  Display.update();
            }
      }

As I said I’m not sure if this is the right way to use the method, but doing it this way the updates are not very reliable, the screen seems to skip every few seconds as if it’s catching up with the updates, if that makes any sense.

So what I’m I doing wrong here?

cheers

Btw, the display mode is set to 60htz.

Try Display.sync2(61) instead of Display.sync(60).

This way your app should skip less to no frames. The reason why sync2 should get 61 instead of 60 is because the sync2 method doesn’t add that small error margin by itself.

I’d written a small test application for comparing different sync methods under cpu load. You can grap it here if you are interested.

I tried sync2(61) and its still causing the graphics to twitch every few seconds.

I take a look at your test app later, I’ll need up update it for the latest lwjgl before it’ll compile.

Cheers onyx.