From 77fb4a724d1ef5d61e585e2512972919dbcdf387 Mon Sep 17 00:00:00 2001 From: Shuanglei Tao Date: Wed, 29 Nov 2023 20:54:42 +0800 Subject: [PATCH] fix mpv render update check it has to happen on the render thread --- source/window.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/source/window.cpp b/source/window.cpp index e9f0514..397dcc2 100644 --- a/source/window.cpp +++ b/source/window.cpp @@ -72,9 +72,7 @@ void Window::initGLFW() { bool Window::init(OptionParser& parser) { mpv->wakeupCb() = [this](Mpv* ctx) { wakeup(); }; - mpv->updateCb() = [this](Mpv* ctx) { - if (ctx->wantRender()) videoWaiter.notify(); - }; + mpv->updateCb() = [this](Mpv* ctx) { videoWaiter.notify(); }; if (!Player::init(parser.options)) return false; for (auto& path : parser.paths) { @@ -115,14 +113,17 @@ void Window::run() { videoWaiter.wait(); if (shutdown) break; - renderVideo(); - wakeup(); + if (mpv->wantRender()) { + renderVideo(); + wakeup(); + } } }); restoreState(); glfwShowWindow(window); + double lastTime = glfwGetTime(); while (!glfwWindowShouldClose(window)) { if (!glfwGetWindowAttrib(window, GLFW_VISIBLE) || glfwGetWindowAttrib(window, GLFW_ICONIFIED)) glfwWaitEvents(); @@ -134,14 +135,13 @@ void Window::run() { render(); updateCursor(); - static double time = 0; double targetDelta = 1.0f / config->Data.Interface.Fps; - double delta = time - ImGui::GetTime(); + double delta = lastTime - glfwGetTime(); if (delta > 0 && delta < targetDelta) glfwWaitEventsTimeout(delta); else - time = ImGui::GetTime(); - time += targetDelta; + lastTime = glfwGetTime(); + lastTime += targetDelta; } shutdown = true;