fix: Crash when framerate falls below 5 FPS (#359)

* This could work

* Testing shows this to work fine, with the added benefit of lower CPU usage

* This should do the trick then
This commit is contained in:
wardwouts
2021-12-04 23:16:15 +01:00
committed by GitHub
parent 5a2e2b1773
commit f0c679fb61

View File

@@ -279,13 +279,15 @@ namespace hex {
}
void Window::loop() {
double timeout;
this->m_lastFrameTime = glfwGetTime();
while (!glfwWindowShouldClose(this->m_window)) {
if (!glfwGetWindowAttrib(this->m_window, GLFW_VISIBLE) || glfwGetWindowAttrib(this->m_window, GLFW_ICONIFIED))
glfwWaitEvents();
else
glfwWaitEventsTimeout(ImGui::IsPopupOpen(ImGuiID(0), ImGuiPopupFlags_AnyPopupId) ? 0 : (this->m_lastFrameTime - glfwGetTime() + 1 / 5.0));
timeout = (1.0 / 5.0) - (glfwGetTime() - this->m_lastFrameTime);
timeout = timeout > 0 ? timeout : 0;
glfwWaitEventsTimeout(ImGui::IsPopupOpen(ImGuiID(0), ImGuiPopupFlags_AnyPopupId) ? 0 : timeout);
this->frameBegin();
this->frame();