Recently built a new computer and after installing IntelliJ + JDK-16, decided to run some graphical applications. Unfortunately, the objects displayed frequently stutter, being drawn one frame, then drawn again several frames later (Should be drawn every frame).
GPU driver is not the issue, however, it seems that as I decrease the time between frames, the object stutters more...
I have not encountered this issue on any of the computers I've run it on before, so the code itself is fine. Is the latest release of the JDK unstable or have there been any updates to the major java graphics libraries that could be causing this issue?
package emre.Boid_Project;
import java.awt.Color;
import java.awt.Graphics;
import java.util.Vector;
import javax.swing.JFrame;
public class Display extends JFrame{
private static final long serialVersionUID = 1L;
private int x_size = 1024;
private int y_size = 1024;
private Flock flock= new Flock(1, x_size, y_size);
public static void main(String[] args) {
new Display();
}
public Display()
{
init();
}
public void paint(Graphics g)
{
Long start_time = System.currentTimeMillis();
g.setColor(Color.BLACK);
g.fillRect(0, 0, x_size, y_size);
g.setColor(Color.YELLOW);
flock.Update();
for(Boid b: flock.getFlock())
{
drawBoid(g, b, 8);
}
}
private void drawBoid(Graphics g, Boid b, int size)
{
Vector<Double> dir_vector = b.getVelocity();
double magnitude = b.VectorMagnitude(dir_vector);
b.MultiplyVector(dir_vector,
new double[] {size/magnitude, size/magnitude});
double x = dir_vector.get(0);
double y = dir_vector.get(1);
//(-y,x)
Vector<Integer> left_vector = new Vector<Integer>();
left_vector.add((int) (b.getRoundedX_pos() + (-0.5*y)));
left_vector.add((int) (b.getRoundedY_pos() + (x*0.5)));
//(y,-x)
Vector<Integer> right_vector = new Vector<Integer>();
right_vector.add((int) (b.getRoundedX_pos() + (y*0.5)));
right_vector.add((int) (b.getRoundedY_pos() + (-0.5*x)));
g.fillPolygon(new int[] {(int) (b.getRoundedX_pos() + x),
left_vector.get(0),
right_vector.get(0),
(int) (b.getRoundedX_pos() + x)},
new int[] {(int) (b.getRoundedY_pos() + y),
left_vector.get(1),
right_vector.get(1),
(int) (b.getRoundedY_pos() + y)},
4);
}
public void init()
{
setDefaultCloseOperation(Display.EXIT_ON_CLOSE);
setSize(x_size,y_size);
setVisible(true);
while(true){
//Time between frames
try {
Thread.sleep(10);
} catch (InterruptedException e) {
e.printStackTrace();
}
repaint();
}
}
}
Hardware + Software: Windows 10, RX 570 + i5 10400, IntelliJ CE 2021, JDK-16