From 83e370d9ded2657f7e1613cb8b7f9a6be8bd7bad Mon Sep 17 00:00:00 2001 From: luiscuenca Date: Thu, 30 Nov 2017 17:40:49 -0700 Subject: [PATCH] add shared pointer --- libraries/ui/src/ui/OffscreenQmlSurface.cpp | 11 +++++------ libraries/ui/src/ui/OffscreenQmlSurface.h | 2 +- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/libraries/ui/src/ui/OffscreenQmlSurface.cpp b/libraries/ui/src/ui/OffscreenQmlSurface.cpp index 98a307e497..5bcf06ce82 100644 --- a/libraries/ui/src/ui/OffscreenQmlSurface.cpp +++ b/libraries/ui/src/ui/OffscreenQmlSurface.cpp @@ -121,7 +121,7 @@ uint64_t uvec2ToUint64(const uvec2& v) { class AudioHandler : public QObject, QRunnable { Q_OBJECT public: - AudioHandler(OffscreenQmlSurface* surface, const QString& deviceName, int runDelayMs = 0, QObject* parent = nullptr) : QObject(parent) { + AudioHandler(QSharedPointer surface, const QString& deviceName, int runDelayMs = 0, QObject* parent = nullptr) : QObject(parent) { _newTargetDevice = deviceName; _runDelayMs = runDelayMs; _surface = surface; @@ -138,9 +138,8 @@ public: if (_runDelayMs > 0) { QThread::msleep(_runDelayMs); } - auto rootItem = _surface->getRootItem(); - if (rootItem && !_surface->getCleaned()) { - for (auto player : rootItem->findChildren()) { + if (!_surface.isNull() && _surface->getRootItem() && !_surface->getCleaned()) { + for (auto player : _surface->getRootItem()->findChildren()) { auto mediaState = player->state(); QMediaService *svc = player->service(); if (nullptr == svc) { @@ -178,7 +177,7 @@ public: private: QString _newTargetDevice; - OffscreenQmlSurface* _surface; + QSharedPointer _surface; int _runDelayMs; }; @@ -705,7 +704,7 @@ void OffscreenQmlSurface::forceQmlAudioOutputDeviceUpdate() { QString deviceName = audioIO->getActiveAudioDevice(QAudio::AudioOutput).deviceName(); int waitForAudioQmlMs = 200; // The audio device need to be change using oth - new AudioHandler(this, deviceName, waitForAudioQmlMs); + new AudioHandler(sharedFromThis(), deviceName, waitForAudioQmlMs); } } diff --git a/libraries/ui/src/ui/OffscreenQmlSurface.h b/libraries/ui/src/ui/OffscreenQmlSurface.h index 371b110aa9..34da11c66c 100644 --- a/libraries/ui/src/ui/OffscreenQmlSurface.h +++ b/libraries/ui/src/ui/OffscreenQmlSurface.h @@ -40,7 +40,7 @@ class QQuickItem; using QmlContextCallback = std::function; -class OffscreenQmlSurface : public QObject { +class OffscreenQmlSurface : public QObject, public QEnableSharedFromThis { Q_OBJECT Q_PROPERTY(bool focusText READ isFocusText NOTIFY focusTextChanged) public: