From 408092d371fd1ec772d5297da429540520d77ba6 Mon Sep 17 00:00:00 2001 From: GhostNaN Date: Thu, 25 Apr 2024 16:45:39 -0400 Subject: [PATCH] Allow bybass of poll() For some reason I'm still unsure of, on Nvidia pro drivers it would get stuck on poll() causing the whole render loop to stall. I also got rid of an unnecessary wl_display_flush() --- src/main.c | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/src/main.c b/src/main.c index b277843..1121713 100644 --- a/src/main.c +++ b/src/main.c @@ -1093,26 +1093,23 @@ int main(int argc, char **argv) { fds[1].fd = wakeup_pipe[0]; fds[1].events = POLLIN; - // Wait for MPV to request a new frame to be drawn - int poll_err = 0; - while (poll_err == 0) { - poll_err = poll(fds, sizeof(fds) / sizeof(fds[0]), 10); // 10ms timeout - if (poll_err == -1 && errno != EINTR) - break; + // Wait for a mpv callback or wl_display event + // 1ms timeout to allow for wl_display_dispatch_pending() + if (poll(fds, sizeof(fds) / sizeof(fds[0]), 1) == -1 && errno != EINTR) + break; - if (halt_info.stop_render_loop) { - halt_info.stop_render_loop = 0; - sleep(2); // Wait at least 2 secs to be killed - } + if (halt_info.stop_render_loop) { + halt_info.stop_render_loop = 0; + sleep(2); // Wait at least 2 secs to be killed } + // Process wl_display events if (fds[0].revents & POLLIN) { if (wl_display_dispatch(state.display) == -1) break; } else { // Avoid frame callback getting stuck if (wl_display_dispatch_pending(state.display) == -1) break; - wl_display_flush(state.display); } // MPV is ready to draw a new frame