From c422b993db21a831a7302580ae5cd0d34a3000cf Mon Sep 17 00:00:00 2001 From: Andrzej Rybczak Date: Mon, 21 Nov 2016 12:04:46 +0100 Subject: [PATCH] Always clear worker after fetching lyrics completed --- src/lyrics.cpp | 15 +++++++++++---- src/lyrics.h | 2 ++ 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/lyrics.cpp b/src/lyrics.cpp index 13a79b6b..49155ebd 100644 --- a/src/lyrics.cpp +++ b/src/lyrics.cpp @@ -227,9 +227,8 @@ void Lyrics::update() } else w << "\nLyrics were not found.\n"; + clearWorker(); m_refresh_window = true; - // Reset worker so it's no longer valid. - m_worker = std::future>(); } } @@ -273,7 +272,10 @@ void Lyrics::fetch(const MPD::Song &s) w.clear(); m_song = s; if (loadLyrics(w, lyricsFilename(m_song))) + { + clearWorker(); m_refresh_window = true; + } else { m_shared_buffer = std::make_shared>(); @@ -295,8 +297,7 @@ void Lyrics::refetchCurrent() } else { - // Get rid of current worker so fetch can restart the process. - m_worker = std::future>(); + clearWorker(); fetch(m_song); } } @@ -417,3 +418,9 @@ boost::optional Lyrics::tryTakeConsumerMessage() } return result; } + +void Lyrics::clearWorker() +{ + m_shared_buffer.reset(); + m_worker = std::future>(); +} diff --git a/src/lyrics.h b/src/lyrics.h index 4b842aed..d891a4c6 100644 --- a/src/lyrics.h +++ b/src/lyrics.h @@ -88,6 +88,8 @@ private: boost::optional message; }; + void clearWorker(); + bool m_refresh_window; size_t m_scroll_begin;