The AnimationTimer is unstable when you minimize a window. It's supposed to run at 60 fps maximum according to the documentation.
I created a simple example which has the AnimationTimer log the difference to the previous frame in milliseconds. It all works as long as you don't access any nodes. But when you tick the checkbox and hence trigger the setTranslate method, the timer runs at insande speed when you minimize the window.
Here's the sample code:
public class AnimationTimerBug extends Application
{
@Override
public void start(Stage primaryStage) throws Exception
{
VBox root = new VBox();
Label randomNode = new Label( "Test Node");
Label label1 = new Label( "\n\n1. Check console, you'll get log outputs at 16 ms.\n2. Minimize the console, the 16 ms will remain.\n3. Check the checkbox.\n\n");
CheckBox checkBox = new CheckBox( "Translate Label");
Label label2 = new Label( "\n4. Now the node moves, we just access the node's translate method. The output is mostly at 16 ms.\n5. Minimize the window. Now the bug occurs, the timer is running at ~0.2 ms instead of 16 ms.");
root.getChildren().addAll( randomNode, label1, checkBox, label2);
Scene scene = new Scene(root, 800, 600);
primaryStage.setScene(scene);
primaryStage.show();
AnimationTimer timer = new AnimationTimer() {
long prev = 0;
long count = 0;
@Override
public void handle(long now) {
System.out.println( (count++) + ": " + (now - prev) / 10e5 + " ms");
if( checkBox.isSelected()) {
randomNode.setTranslateX( now % 10);
}
prev = now;
}
};
timer.start();
}
public static void main(String[] args)
{
launch(args);
}
}
The normal output is this:
149: 15.981437 ms
150: 16.016558 ms
151: 16.057084 ms
152: 15.997947 ms
153: 15.945113 ms
154: 16.032168 ms
155: 15.994045 ms
156: 16.015057 ms
157: 15.958022 ms
158: 16.043275 ms
159: 16.018359 ms
160: 15.965827 ms
When you minimize the window, it remains the same.
It gets irregular when you click the checkbox:
166: 8.142614 ms
167: 16.02016 ms
168: 9.228996 ms
169: 6.835293 ms
170: 15.964626 ms
171: 15.976933 ms
172: 16.01866 ms
173: 12.112907 ms
174: 3.887441 ms
175: 16.028566 ms
176: 15.951417 ms
177: 16.030668 ms
178: 16.096708 ms
179: 15.888678 ms
And when you minimize the window when the checkbox is selected, you'll get this:
1214: 15.36635 ms
1215: 16.014757 ms
1216: 0.167505 ms
1217: 0.120976 ms
1218: 0.118575 ms
1219: 0.133884 ms
1220: 0.148293 ms
1221: 0.134785 ms
1222: 0.168706 ms
1223: 0.131782 ms
1224: 0.118275 ms
1225: 0.105066 ms
This happens on Win7 with Java8u25 and Java8u33.
I created a simple example which has the AnimationTimer log the difference to the previous frame in milliseconds. It all works as long as you don't access any nodes. But when you tick the checkbox and hence trigger the setTranslate method, the timer runs at insande speed when you minimize the window.
Here's the sample code:
public class AnimationTimerBug extends Application
{
@Override
public void start(Stage primaryStage) throws Exception
{
VBox root = new VBox();
Label randomNode = new Label( "Test Node");
Label label1 = new Label( "\n\n1. Check console, you'll get log outputs at 16 ms.\n2. Minimize the console, the 16 ms will remain.\n3. Check the checkbox.\n\n");
CheckBox checkBox = new CheckBox( "Translate Label");
Label label2 = new Label( "\n4. Now the node moves, we just access the node's translate method. The output is mostly at 16 ms.\n5. Minimize the window. Now the bug occurs, the timer is running at ~0.2 ms instead of 16 ms.");
root.getChildren().addAll( randomNode, label1, checkBox, label2);
Scene scene = new Scene(root, 800, 600);
primaryStage.setScene(scene);
primaryStage.show();
AnimationTimer timer = new AnimationTimer() {
long prev = 0;
long count = 0;
@Override
public void handle(long now) {
System.out.println( (count++) + ": " + (now - prev) / 10e5 + " ms");
if( checkBox.isSelected()) {
randomNode.setTranslateX( now % 10);
}
prev = now;
}
};
timer.start();
}
public static void main(String[] args)
{
launch(args);
}
}
The normal output is this:
149: 15.981437 ms
150: 16.016558 ms
151: 16.057084 ms
152: 15.997947 ms
153: 15.945113 ms
154: 16.032168 ms
155: 15.994045 ms
156: 16.015057 ms
157: 15.958022 ms
158: 16.043275 ms
159: 16.018359 ms
160: 15.965827 ms
When you minimize the window, it remains the same.
It gets irregular when you click the checkbox:
166: 8.142614 ms
167: 16.02016 ms
168: 9.228996 ms
169: 6.835293 ms
170: 15.964626 ms
171: 15.976933 ms
172: 16.01866 ms
173: 12.112907 ms
174: 3.887441 ms
175: 16.028566 ms
176: 15.951417 ms
177: 16.030668 ms
178: 16.096708 ms
179: 15.888678 ms
And when you minimize the window when the checkbox is selected, you'll get this:
1214: 15.36635 ms
1215: 16.014757 ms
1216: 0.167505 ms
1217: 0.120976 ms
1218: 0.118575 ms
1219: 0.133884 ms
1220: 0.148293 ms
1221: 0.134785 ms
1222: 0.168706 ms
1223: 0.131782 ms
1224: 0.118275 ms
1225: 0.105066 ms
This happens on Win7 with Java8u25 and Java8u33.
- relates to
-
JDK-8136528 Minimized window busy loop (cause and fix for JDK-8088772)
-
- Open
-