Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FPS counter shows LONG_MIN if renderTime.count() is 0 #421

Closed
nabijaczleweli opened this issue May 21, 2019 · 3 comments
Closed

FPS counter shows LONG_MIN if renderTime.count() is 0 #421

nabijaczleweli opened this issue May 21, 2019 · 3 comments
Labels
Milestone

Comments

@nabijaczleweli
Copy link
Contributor

nabijaczleweli commented May 21, 2019

System information

SolveSpace version: 3.0~39c34809

Operating system: Windows 10

Expected behavior

The counter checks if the count is zero and prevents casting an inf to a long.

Actual behavior

The FPS counter overflows the long argument and displays it.

Additional information

Screenshot

@whitequark whitequark added the bug label May 21, 2019
@whitequark
Copy link
Contributor

What about this?

diff --git a/src/draw.cpp b/src/draw.cpp
index 3f13b5d..b9ddcb4 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();

@nabijaczleweli
Copy link
Contributor Author

Yep, that does it!

Screenshot

@whitequark
Copy link
Contributor

Fixed in 9500487.

@whitequark whitequark added this to the 3.0 milestone May 23, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants