From e2ff460dbd15cb8915e9638ec8d6ed7d1e903ebd Mon Sep 17 00:00:00 2001 From: Leterax Date: Mon, 2 Dec 2024 13:57:17 +0100 Subject: [PATCH] Fix Timer FPS calculation to avoid division by zero on the first frame --- moderngl_window/timers/clock.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/moderngl_window/timers/clock.py b/moderngl_window/timers/clock.py index 35b061f..68db0ae 100644 --- a/moderngl_window/timers/clock.py +++ b/moderngl_window/timers/clock.py @@ -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: