@@ -559,11 +559,16 @@ public static boolean isRunning() {
559559 * @return Double value, based on the information requested.
560560 */
561561 public static double getFPSData (FPSValue dataType ) {
562- int [] validFPSValues = Arrays .copyOfRange (fpsLog , 0 , Math .min (fpsLog .length , fpsLogIndex ));
562+ int validFPSIndex = fpsLogIndex == -1 ? 0 : fpsLogIndex ;
563+ int [] validFPSValues = Arrays .copyOfRange (
564+ fpsLog ,
565+ 0 ,
566+ Math .min (fpsLog .length , validFPSIndex )
567+ );
563568
564569 switch (dataType ) {
565570 case Current :
566- return (fpsLog [fpsLogIndex % 100 ] != -1 ) ? fpsLog [fpsLogIndex % 100 ] : 0 ;
571+ return (fpsLog [validFPSIndex % 100 ] != -1 ) ? fpsLog [fpsLogIndex % 100 ] : 0 ;
567572 case Average :
568573 return (double ) totalFPS / (double ) fpsLogIndex ;
569574 case Highest :
@@ -775,6 +780,7 @@ private static void initEngine() {
775780 gameManager .init (canvas );
776781 gameManager .initBehaviors ();
777782
783+ fpsLogIndex = -1 ;
778784 fpsLogger .scheduleWithFixedDelay (() -> {
779785 FastJEngine .logFPS (drawFrames );
780786 drawFrames = 0 ;
@@ -839,7 +845,7 @@ private static void exit() {
839845 fpsLogger = null ;
840846 drawFrames = 0 ;
841847 totalFPS = 0 ;
842- fpsLogIndex = 0 ;
848+ fpsLogIndex = - 1 ;
843849
844850 // HW acceleration
845851 hwAccel = null ;
@@ -878,7 +884,7 @@ private static void logFPS(int frames) {
878884 * @param frames The count of frames rendered.
879885 */
880886 private static void storeFPS (int frames ) {
881- fpsLog [fpsLogIndex % 100 ] = frames ;
887+ fpsLog [( fpsLogIndex + 1 ) % 100 ] = frames ;
882888 fpsLogIndex ++;
883889 totalFPS += frames ;
884890 }
0 commit comments