From 0ce1281eca391c18cc0f28b29a34e8ebbe8b2b6a Mon Sep 17 00:00:00 2001 From: RickyRister Date: Fri, 4 Jul 2025 22:13:00 -0700 Subject: [PATCH] Fix segfault from status bar Pass just the relevant data through the signals to the status bar, instead of passing the entire Work object. That way the data is detached from the Work object and we won't segfault when Work self-deletes before status bar tries to use that data. --- ...e_loader_request_status_display_widget.cpp | 23 +++++++++---------- ...ure_loader_request_status_display_widget.h | 6 +++-- .../picture_loader_status_bar.cpp | 7 +++--- .../picture_loader_status_bar.h | 4 ++-- .../picture_loader/picture_loader_worker.cpp | 4 ++-- .../ui/picture_loader/picture_loader_worker.h | 4 ++-- 6 files changed, 24 insertions(+), 24 deletions(-) diff --git a/cockatrice/src/client/ui/picture_loader/picture_loader_request_status_display_widget.cpp b/cockatrice/src/client/ui/picture_loader/picture_loader_request_status_display_widget.cpp index 3647eb71e..a792087d5 100644 --- a/cockatrice/src/client/ui/picture_loader/picture_loader_request_status_display_widget.cpp +++ b/cockatrice/src/client/ui/picture_loader/picture_loader_request_status_display_widget.cpp @@ -2,23 +2,22 @@ PictureLoaderRequestStatusDisplayWidget::PictureLoaderRequestStatusDisplayWidget(QWidget *parent, const QUrl &_url, - PictureLoaderWorkerWork *worker) + const CardInfoPtr &card, + const QString &setName) : QWidget(parent) { layout = new QHBoxLayout(this); - if (worker->cardToDownload.getCard()) { - name = new QLabel(this); - name->setText(worker->cardToDownload.getCard()->getName()); - setShortname = new QLabel(this); - setShortname->setText(worker->cardToDownload.getSetName()); - providerId = new QLabel(this); - providerId->setText(worker->cardToDownload.getCard()->getProperty("uuid")); + name = new QLabel(this); + name->setText(card->getName()); + setShortname = new QLabel(this); + setShortname->setText(setName); + providerId = new QLabel(this); + providerId->setText(card->getProperty("uuid")); - layout->addWidget(name); - layout->addWidget(setShortname); - layout->addWidget(providerId); - } + layout->addWidget(name); + layout->addWidget(setShortname); + layout->addWidget(providerId); startTime = new QLabel(QDateTime::currentDateTime().toString(), this); elapsedTime = new QLabel("0", this); diff --git a/cockatrice/src/client/ui/picture_loader/picture_loader_request_status_display_widget.h b/cockatrice/src/client/ui/picture_loader/picture_loader_request_status_display_widget.h index 01eee1b48..46a809e47 100644 --- a/cockatrice/src/client/ui/picture_loader/picture_loader_request_status_display_widget.h +++ b/cockatrice/src/client/ui/picture_loader/picture_loader_request_status_display_widget.h @@ -10,8 +10,10 @@ class PictureLoaderRequestStatusDisplayWidget : public QWidget { Q_OBJECT public: - PictureLoaderRequestStatusDisplayWidget(QWidget *parent, const QUrl &url, PictureLoaderWorkerWork *worker); - PictureLoaderWorkerWork *worker; + PictureLoaderRequestStatusDisplayWidget(QWidget *parent, + const QUrl &url, + const CardInfoPtr &card, + const QString &setName); void setFinished() { diff --git a/cockatrice/src/client/ui/picture_loader/picture_loader_status_bar.cpp b/cockatrice/src/client/ui/picture_loader/picture_loader_status_bar.cpp index 67b50a1f2..a2beeac1f 100644 --- a/cockatrice/src/client/ui/picture_loader/picture_loader_status_bar.cpp +++ b/cockatrice/src/client/ui/picture_loader/picture_loader_status_bar.cpp @@ -38,15 +38,14 @@ void PictureLoaderStatusBar::cleanOldEntries() } } -void PictureLoaderStatusBar::addQueuedImageLoad(const QUrl &url, PictureLoaderWorkerWork *worker) +void PictureLoaderStatusBar::addQueuedImageLoad(const QUrl &url, const CardInfoPtr &card, const QString &setName) { - loadLog->addSettingsWidget(new PictureLoaderRequestStatusDisplayWidget(loadLog, url, worker)); + loadLog->addSettingsWidget(new PictureLoaderRequestStatusDisplayWidget(loadLog, url, card, setName)); progressBar->setMaximum(progressBar->maximum() + 1); } -void PictureLoaderStatusBar::addSuccessfulImageLoad(const QUrl &url, PictureLoaderWorkerWork *worker) +void PictureLoaderStatusBar::addSuccessfulImageLoad(const QUrl &url) { - Q_UNUSED(worker) progressBar->setValue(progressBar->value() + 1); for (PictureLoaderRequestStatusDisplayWidget *statusDisplayWidget : loadLog->popup->findChildren()) { diff --git a/cockatrice/src/client/ui/picture_loader/picture_loader_status_bar.h b/cockatrice/src/client/ui/picture_loader/picture_loader_status_bar.h index 6a507cbb0..6f5111a34 100644 --- a/cockatrice/src/client/ui/picture_loader/picture_loader_status_bar.h +++ b/cockatrice/src/client/ui/picture_loader/picture_loader_status_bar.h @@ -15,8 +15,8 @@ public: explicit PictureLoaderStatusBar(QWidget *parent); public slots: - void addQueuedImageLoad(const QUrl &url, PictureLoaderWorkerWork *worker); - void addSuccessfulImageLoad(const QUrl &url, PictureLoaderWorkerWork *worker); + void addQueuedImageLoad(const QUrl &url, const CardInfoPtr &card, const QString &setName); + void addSuccessfulImageLoad(const QUrl &url); void cleanOldEntries(); private: diff --git a/cockatrice/src/client/ui/picture_loader/picture_loader_worker.cpp b/cockatrice/src/client/ui/picture_loader/picture_loader_worker.cpp index 00c157e34..5bab2b265 100644 --- a/cockatrice/src/client/ui/picture_loader/picture_loader_worker.cpp +++ b/cockatrice/src/client/ui/picture_loader/picture_loader_worker.cpp @@ -72,7 +72,7 @@ void PictureLoaderWorker::queueRequest(const QUrl &url, PictureLoaderWorkerWork makeRequest(url, worker); } else { requestLoadQueue.append(qMakePair(url, worker)); - emit imageLoadQueued(url, worker); + emit imageLoadQueued(url, worker->cardToDownload.getCard(), worker->cardToDownload.getSetName()); processQueuedRequests(); } } @@ -82,7 +82,7 @@ QNetworkReply *PictureLoaderWorker::makeRequest(const QUrl &url, PictureLoaderWo // Check for cached redirects QUrl cachedRedirect = getCachedRedirect(url); if (!cachedRedirect.isEmpty()) { - emit imageLoadSuccessful(url, worker); + emit imageLoadSuccessful(url); return makeRequest(cachedRedirect, worker); } diff --git a/cockatrice/src/client/ui/picture_loader/picture_loader_worker.h b/cockatrice/src/client/ui/picture_loader/picture_loader_worker.h index 11a92e32a..6a159c167 100644 --- a/cockatrice/src/client/ui/picture_loader/picture_loader_worker.h +++ b/cockatrice/src/client/ui/picture_loader/picture_loader_worker.h @@ -71,8 +71,8 @@ private slots: signals: void imageLoadEnqueued(const CardInfoPtr &card); void imageLoaded(CardInfoPtr card, const QImage &image); - void imageLoadQueued(const QUrl &url, PictureLoaderWorkerWork *worker); - void imageLoadSuccessful(const QUrl &url, PictureLoaderWorkerWork *worker); + void imageLoadQueued(const QUrl &url, const CardInfoPtr &card, const QString &setName); + void imageLoadSuccessful(const QUrl &url); }; #endif // PICTURE_LOADER_WORKER_H