Skip to content

Commit

Permalink
Fix Timer FPS calculation to avoid division by zero on the first frame
Browse files Browse the repository at this point in the history
  • Loading branch information
Leterax committed Dec 2, 2024
1 parent 2ee18ef commit e2ff460
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion moderngl_window/timers/clock.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,13 @@ def next_frame(self) -> tuple[float, float]:
self._frames += 1
current = self.time
delta, self._last_frame = current - self._last_frame, current
self._fps = 1.0 / delta

# Avoid division by zero on first frame
if delta > 0:
self._fps = 1.0 / delta
else:
self._fps = 0.0

return current, delta

def start(self) -> None:
Expand Down

0 comments on commit e2ff460

Please sign in to comment.