From a3ff7d2225afe0cf3c01f7afb0e307dfc6cd6859 Mon Sep 17 00:00:00 2001 From: Charles Magahern Date: Wed, 23 Dec 2020 19:28:49 -0700 Subject: [PATCH] Fix crash when closing the window --- src/app.hpp | 6 ++++++ src/artwork.hpp | 12 +++++++++--- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/app.hpp b/src/app.hpp index 52f47f1..c17c4e1 100644 --- a/src/app.hpp +++ b/src/app.hpp @@ -41,6 +41,12 @@ struct SomaFM _reload_channels(); } + ~SomaFM() + { + _tree_artwork_queue.set_completion_callback([](auto _){}); + _now_playing_artwork_queue.set_completion_callback([](auto _){}); + } + int run() { diff --git a/src/artwork.hpp b/src/artwork.hpp index a8a6963..c258710 100644 --- a/src/artwork.hpp +++ b/src/artwork.hpp @@ -93,11 +93,13 @@ private: std::unique_lock lock(_mut); _cv.wait(lock, [this] { return !_queue.empty() || !_running; }); - next = _queue.front(); - _queue.pop(); + if (!_queue.empty()) { + next = _queue.front(); + _queue.pop(); + } } - if (next && _completion) { + if (_running && next && _completion) { _completion(_get_result(*next)); } @@ -179,6 +181,10 @@ struct ArtworkWorkQueue set_completion_callback(const ArtworkCompletionCb &cb) { _completion_cb = cb; + + for (auto &worker : _workers) { + worker.set_completion_callback(cb); + } } void -- 2.45.2