From 248f1d8596b69d58a885130bcada4799f116341c Mon Sep 17 00:00:00 2001 From: Jim Broadus Date: Wed, 20 Feb 2019 00:03:44 -0800 Subject: [PATCH] Prevent UI hang during device scan. (#6291) When unmounting a device, the ConnectedDevice object is destroyed. The FileSystemDevice destructor waits on its worker thread. If a scan is in progress, this will block until completion. There is an existing Stop method in the LibraryWatcher class that is intended to stop long running operations. To fix, or at least significantly shorten this hang, we'll call this before waiting for the thread to exit. Also add a stop_requested check in the cover art scan. In addition, add a call to Stop in the Library destructor, which has a similar usage. --- src/devices/filesystemdevice.cpp | 1 + src/library/library.cpp | 1 + src/library/librarywatcher.cpp | 2 ++ 3 files changed, 4 insertions(+) diff --git a/src/devices/filesystemdevice.cpp b/src/devices/filesystemdevice.cpp index 3b1bd3ec0..342384718 100644 --- a/src/devices/filesystemdevice.cpp +++ b/src/devices/filesystemdevice.cpp @@ -71,6 +71,7 @@ void FilesystemDevice::Init() { } FilesystemDevice::~FilesystemDevice() { + watcher_->Stop(); watcher_->deleteLater(); watcher_thread_->exit(); watcher_thread_->wait(); diff --git a/src/library/library.cpp b/src/library/library.cpp index 6603e6043..60aafabda 100644 --- a/src/library/library.cpp +++ b/src/library/library.cpp @@ -121,6 +121,7 @@ Library::Library(Application* app, QObject* parent) } Library::~Library() { + watcher_->Stop(); watcher_->deleteLater(); watcher_thread_->exit(); watcher_thread_->wait(5000 /* five seconds */); diff --git a/src/library/librarywatcher.cpp b/src/library/librarywatcher.cpp index 4cb7d934b..b77843c32 100644 --- a/src/library/librarywatcher.cpp +++ b/src/library/librarywatcher.cpp @@ -678,6 +678,8 @@ QString LibraryWatcher::PickBestImage(const QStringList& images) { QString biggest_path; for (const QString& path : filtered) { + if (stop_requested_) return ""; + QImage image(path); if (image.isNull()) continue;