LWJGL resize and delta

I have a resizable LWJGL display, it works fine, just that the timing doesn’t calculate that there was a long delay between the frame were I wasn’t resizing, and the frame that I was resizing (Current).

So delta (Time in ms between frames), freaks out and thinks my computer lagged.

Were I’m using deta:

 sunX += 0.3f * delta; 

My timing class:

package passage.games.pdday.handling;

import org.lwjgl.Sys;

public class TimingHandler {
	
	private long lastFrame;
	private float fps;
	private float frame;
	private long lastFPS;
	
	public void init(){	
		getDelta();
		lastFPS = getTime();
	}
	
	public void tick(int delta){
		updateFPS();
	}
	
	public int getDelta() {
	    long time = getTime();
	    int delta = (int) (time - lastFrame);
	    lastFrame = time;
 
	    return delta;
	}
	
	public long getTime() {
	    return (Sys.getTime() * 1000) / Sys.getTimerResolution();
	}
	
	public void updateFPS() {
		if (getTime() - lastFPS > 1000) {
			fps = frame;
			frame = 0;
			lastFPS += 1000;
		}
		frame++;
	}

	public float getFps() {
		return fps;
	}
}

      while(!Display.isCloseRequested()){
			int delta = timingObj.getDelta();
			
			render();
			tick(delta);
		}

I’d just pause the game when the window is being resized, and resume once the resize is complete. :slight_smile:

A simplistic but working approach I used to handle these situations is to simply cap the maximum delta. E.g. something like:

   public int getDelta() {
       long time = getTime();
       int delta = Math.min(100, (int) (time - lastFrame));
       lastFrame = time;
 
       return delta;
   }
   

This would simply mean that delta will never be larger than 0.1 second (or any value you prefer). I dont really see a downside to this (if the game runs very slowly things may get a bit choppy because youre throwing away delta time. But hey, by then the game is choppy as hell already so no worries).

Also, I highly recommend you take a close look at good timing practices, for example in this article by GaffferOnGames. Generally you want to avoid the tick(delta) function getting a variable delta value because this can mess up physics and other things in many situations.