0

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

Emre
  • 29
  • 2
  • 1
    Describe your new computer briefly, hardware and software. Exactly what Java implementation did you install? – Basil Bourque Apr 10 '21 at 01:07
  • See if there is a correlation between the stuttering and STW garbage collection events. – Stephen C Apr 10 '21 at 01:16
  • @StephenC The stuttering is not correlated with garbage collection, interestingly enough stuttering actually improves following a garbage collection – Emre Apr 22 '21 at 21:00
  • Have you tried disabling graphics hardware acceleration? https://stackoverflow.com/questions/18754803 – Stephen C Apr 23 '21 at 00:58
  • I notice that you are making some questionable assumptions here. For example: 1) You seem to have dismissed the possibility of a GPU driver issue ... for no reason that I can see. 2) *"I have not encountered this issue on any of the computers I've run it on before, so the code itself is fine."* - That is an incorrect inference. There are many kinds of Java application code bug that will manifest on one platform and not on another. – Stephen C Apr 23 '21 at 01:03
  • (I don't **know** if this is due to an application bug, or not ... but that's not the point. If you say "there is no bug", then most people will not bother looking for one. What if you are wrong? Likewise for GPUs ...) – Stephen C Apr 23 '21 at 01:07
  • For the GPU driver, I should clarify that any potential driver issue would be due to some incompatibility with the current AMD driver I am using (Adrenalin 21.4.1), I've done work trying to solve this before coming here and ensured that the driver has not been incorrectly installed. That's why I'm asking if anyone with similar hardware has had the same problem. As for java application code bugs, I don't see any potential evidence for one here as all computers I've run with the code have been using JDK-16.0.1 and the same version of Windows 10. – Emre Apr 25 '21 at 05:32

0 Answers0