From 69f344a439eeb6931a85265b6223b04ee24e7966 Mon Sep 17 00:00:00 2001 From: Vlad Zahorodnii Date: Mon, 5 Feb 2024 16:24:48 +0200 Subject: [PATCH] plugins/screenshot: Cache screenshot attributes When a QPromise reports results, it's not necessary that the QFutureWatcher is going to report it immediately. That can happen at some point in the future, which is okay according to the QFuture api contract. Due to that, we cannot assume that the stored Output and EffectWindow objects pointers are valid when the QFutureWatcher::finished is emitted. --- src/plugins/screenshot/screenshotdbusinterface2.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/plugins/screenshot/screenshotdbusinterface2.cpp b/src/plugins/screenshot/screenshotdbusinterface2.cpp index 0d11d7a1d7..9d8a28645e 100644 --- a/src/plugins/screenshot/screenshotdbusinterface2.cpp +++ b/src/plugins/screenshot/screenshotdbusinterface2.cpp @@ -176,7 +176,7 @@ public: QVariantMap attributes() const override; private: - Output *m_screen; + QString m_name; }; class ScreenShotSourceArea2 : public ScreenShotSource2 @@ -197,7 +197,7 @@ public: QVariantMap attributes() const override; private: - EffectWindow *m_window; + QUuid m_internalId; }; class ScreenShotSinkPipe2 : public QObject @@ -248,14 +248,14 @@ ScreenShotSourceScreen2::ScreenShotSourceScreen2(ScreenShotEffect *effect, Output *screen, ScreenShotFlags flags) : ScreenShotSource2(effect->scheduleScreenShot(screen, flags)) - , m_screen(screen) + , m_name(screen->name()) { } QVariantMap ScreenShotSourceScreen2::attributes() const { return QVariantMap{ - {QStringLiteral("screen"), m_screen->name()}, + {QStringLiteral("screen"), m_name}, }; } @@ -270,14 +270,14 @@ ScreenShotSourceWindow2::ScreenShotSourceWindow2(ScreenShotEffect *effect, EffectWindow *window, ScreenShotFlags flags) : ScreenShotSource2(effect->scheduleScreenShot(window, flags)) - , m_window(window) + , m_internalId(window->internalId()) { } QVariantMap ScreenShotSourceWindow2::attributes() const { return QVariantMap{ - {QStringLiteral("windowId"), m_window->internalId().toString()}, + {QStringLiteral("windowId"), m_internalId.toString()}, }; }