From 9500487a3f7f4ed9f9e5a7bd81dde27594640248 Mon Sep 17 00:00:00 2001 From: whitequark Date: Tue, 21 May 2019 22:51:28 +0000 Subject: [PATCH] Fix an edge case with fps measured as infinite. If the timer is not sufficiently high resolution but the graphics card is fast, we can get renderTime.count() == 0. --- src/draw.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/draw.cpp b/src/draw.cpp index 3f13b5d1..b9ddcb45 100644 --- a/src/draw.cpp +++ b/src/draw.cpp @@ -888,7 +888,7 @@ void GraphicsWindow::Paint() { // Also display an fps counter. RgbaColor renderTimeColor; - if(1000 / renderTime.count() < 60) { + if(renderTime.count() > 16.67) { // We aim for a steady 60fps; draw the counter in red when we're slower. renderTimeColor = { 255, 0, 0, 255 }; } else { @@ -896,7 +896,7 @@ void GraphicsWindow::Paint() { } uiCanvas.DrawBitmapText(ssprintf("rendered in %ld ms (%ld 1/s)", (long)renderTime.count(), - (long)(1000/renderTime.count())), + (long)(1000 / std::max(0.1, renderTime.count()))), 5, 5, renderTimeColor); canvas->FlushFrame();