[PictureLoader] Fix worker leak (#6001)

This commit is contained in:
RickyRister 2025-06-22 15:29:20 -07:00 committed by GitHub
parent c1f12f52ae
commit 66e44f3448
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 13 additions and 8 deletions

View file

@ -16,7 +16,7 @@
QStringList PictureLoaderWorkerWork::md5Blacklist = QStringList() << "db0c48db407a907c16ade38de048a441";
PictureLoaderWorkerWork::PictureLoaderWorkerWork(const PictureLoaderWorker *worker, const CardInfoPtr &toLoad)
: QThread(nullptr), cardToDownload(toLoad), picDownload(SettingsCache::instance().getPicDownload())
: QObject(nullptr), cardToDownload(toLoad), picDownload(SettingsCache::instance().getPicDownload())
{
// Hook up signals to the orchestrator
connect(this, &PictureLoaderWorkerWork::requestImageDownload, worker, &PictureLoaderWorker::queueRequest,
@ -32,12 +32,12 @@ PictureLoaderWorkerWork::PictureLoaderWorkerWork(const PictureLoaderWorker *work
connect(pictureLoaderThread, &QThread::started, this, &PictureLoaderWorkerWork::startNextPicDownload);
pictureLoaderThread->start(QThread::LowPriority);
}
// clean up worker once loading finishes
connect(this, &PictureLoaderWorkerWork::imageLoaded, this, &QObject::deleteLater);
connect(this, &QObject::destroyed, pictureLoaderThread, &QThread::quit);
connect(pictureLoaderThread, &QThread::finished, pictureLoaderThread, &QObject::deleteLater);
PictureLoaderWorkerWork::~PictureLoaderWorkerWork()
{
pictureLoaderThread->deleteLater();
pictureLoaderThread->start(QThread::LowPriority);
}
void PictureLoaderWorkerWork::startNextPicDownload()

View file

@ -20,12 +20,12 @@
inline Q_LOGGING_CATEGORY(PictureLoaderWorkerWorkLog, "picture_loader.worker");
class PictureLoaderWorker;
class PictureLoaderWorkerWork : public QThread
class PictureLoaderWorkerWork : public QObject
{
Q_OBJECT
public:
explicit PictureLoaderWorkerWork(const PictureLoaderWorker *worker, const CardInfoPtr &toLoad);
~PictureLoaderWorkerWork() override;
PictureToLoad cardToDownload;
@ -46,6 +46,11 @@ private slots:
void picDownloadChanged();
signals:
/**
* Emitted when this worker has successfully loaded the image or has exhausted all attempts at loading the image.
* Failures are represented by an empty QImage.
* Note that this object will delete itself as this signal is emitted.
*/
void imageLoaded(CardInfoPtr card, const QImage &image);
void requestImageDownload(const QUrl &url, PictureLoaderWorkerWork *instance);
};