Browse Source

throttle tight loop over glfwWaitEvents with sleep (#2151)

* throttle tight loop over glfwWaitEvents with sleep

* restore changes in Main
Alec Jacobson 2 years ago
parent
commit
e4b8bfb28d
1 changed files with 8 additions and 9 deletions
  1. 8 9
      include/igl/opengl/glfw/Viewer.cpp

+ 8 - 9
include/igl/opengl/glfw/Viewer.cpp

@@ -240,19 +240,18 @@ namespace glfw
       if(core().is_animating || frame_counter++ < num_extra_frames)
       {
         glfwPollEvents();
-        // In microseconds
-        double duration = 1000000.*(get_seconds()-tic);
-        const double min_duration = 1000000./core().animation_max_fps;
-        if(duration<min_duration)
-        {
-          std::this_thread::sleep_for(std::chrono::microseconds((int)(min_duration-duration)));
-        }
-      }
-      else
+      }else
       {
         glfwWaitEvents();
         frame_counter = 0;
       }
+      // In microseconds
+      double duration = 1000000.*(get_seconds()-tic);
+      const double min_duration = 1000000./core().animation_max_fps;
+      if(duration<min_duration)
+      {
+        std::this_thread::sleep_for(std::chrono::microseconds((int)(min_duration-duration)));
+      }
       if (!loop)
         return !glfwWindowShouldClose(window);