From dbf127983b9c287b81bee6f875ec259a1669029b Mon Sep 17 00:00:00 2001 From: Kubat <mael.martin31@gmail.com> Date: Mon, 20 Apr 2020 15:39:10 +0200 Subject: [PATCH] Solve segfault and always check mpv events --- src/module/module_sdl2.c | 20 ++++++-------------- src/module/mpv.c | 2 +- 2 files changed, 7 insertions(+), 15 deletions(-) diff --git a/src/module/module_sdl2.c b/src/module/module_sdl2.c index 40f738d7..85091c7f 100644 --- a/src/module/module_sdl2.c +++ b/src/module/module_sdl2.c @@ -36,7 +36,6 @@ struct module_sdl2_window { pthread_mutex_t mtx; struct lkt_thread self; volatile int launched; - volatile int mpv_wakeup; }; /* Thread related functions */ @@ -48,19 +47,19 @@ sdl_thread__(struct lkt_thread_arg *arg) struct lkt_thread *self = arg->self; struct module_sdl2_window *sdl2 = win->window; SDL_Event event; - uint64_t flags, redraw = 0; - int w, h; + uint64_t flags; + int w, h, redraw = 0; free(arg); (void) self; RETURN_UNLESS(sdl2 && sdl2->window, "Big nope here, the sdl window pointer is NULL", NULL); fprintf(stderr, " * Started SDL thread\n"); loop: - SDL_PollEvent(&event); + if (SDL_PollEvent(&event)) + sched_yield(); switch (event.type) { case SDL_QUIT: - sched_yield(); break; case SDL_WINDOWEVENT: @@ -92,9 +91,6 @@ loop: if (flags & MPV_RENDER_UPDATE_FRAME) redraw = 1; } - /* Handle mpv events are not done here. */ - if (event.type == wakeup_on_mpv_events) - sdl2->mpv_wakeup = 1; } if (redraw) { @@ -336,10 +332,6 @@ module_sdl2_handle_events(struct lkt_win *const win, sqlite3 *db, enum mpd_idle_ { struct module_sdl2_window *sdl2 = win->window; RETURN_UNLESS(sdl2, "Can't handle events from a NULL window", false); - if (sdl2->mpv_wakeup) { - sdl2->mpv_wakeup = 0; - return ! lmpv_handle(win, (mpv_handle *) sdl2->mpv, db, mpd_idle_events, - (int *) &sdl2->mpv_time_pos, (int *) &sdl2->mpv_duration); - } else - return true; + return ! lmpv_handle(win, (mpv_handle *) sdl2->mpv, db, mpd_idle_events, + (int *) &sdl2->mpv_time_pos, (int *) &sdl2->mpv_duration); } diff --git a/src/module/mpv.c b/src/module/mpv.c index 7da88198..c5d5626c 100644 --- a/src/module/mpv.c +++ b/src/module/mpv.c @@ -10,7 +10,7 @@ void lmpv_free(mpv_handle **ctx) { - RETURN_UNLESS(ctx, "Missing mpv ctx", NOTHING); + RETURN_UNLESS(ctx && *ctx, "Missing mpv ctx", NOTHING); static const char *cmd[] = {"quit", NULL}; mpv_command(*ctx, cmd); mpv_destroy(*ctx); -- GitLab