From cad1e9739df79e52d647f04e5ffd0ae271dbf800 Mon Sep 17 00:00:00 2001 From: Martin Pulec Date: Tue, 28 Jun 2022 16:44:08 +0200 Subject: [PATCH] GL: fixed crash if exiting with paused frame The control flow was a bit incorrect - pause should be handled prior to current_frame update. Anyways, the whole stuff is still a bit ugly (namely the pop_frame stuff + locking). Delaying frame pop was a kind of optimization - not sure if it is worth it. --- src/video_display/gl.cpp | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/src/video_display/gl.cpp b/src/video_display/gl.cpp index 3d8cdf8bd..3db1ef845 100644 --- a/src/video_display/gl.cpp +++ b/src/video_display/gl.cpp @@ -1032,9 +1032,9 @@ static void gl_render(struct state_gl *s, char *data) gl_check_error(); } -static void pop_frame(struct state_gl *s) +/// @note lk will be unlocked! +static void pop_frame(struct state_gl *s, unique_lock &lk) { - unique_lock lk(s->lock); s->frame_queue.pop(); lk.unlock(); s->frame_consumed_cv.notify_one(); @@ -1089,7 +1089,16 @@ static void gl_process_frames(struct state_gl *s) return; } frame = s->frame_queue.front(); - + if (!frame) { + pop_frame(s, lk); + return; + } + if (s->paused) { + vf_recycle(frame); + s->free_frame_queue.push(frame); + pop_frame(s, lk); + return; + } if (s->current_frame) { vf_recycle(s->current_frame); s->free_frame_queue.push(s->current_frame); @@ -1097,19 +1106,6 @@ static void gl_process_frames(struct state_gl *s) s->current_frame = frame; } - if (!frame) { - pop_frame(s); - return; - } - - if (s->paused) { - pop_frame(s); - unique_lock lk(s->lock); - vf_recycle(frame); - s->free_frame_queue.push(frame); - return; - } - if (!video_desc_eq(video_desc_from_frame(frame), s->current_display_desc)) { gl_reconfigure_screen(s, video_desc_from_frame(frame)); } @@ -1133,7 +1129,10 @@ static void gl_process_frames(struct state_gl *s) glfwSwapBuffers(s->window); } log_msg(LOG_LEVEL_DEBUG, "Render buffer %dx%d\n", frame->tiles[0].width, frame->tiles[0].height); - pop_frame(s); + { + unique_lock lk(s->lock); + pop_frame(s, lk); + } /* FPS Data, this is pretty ghetto though.... */ s->frames++;