eliminate signal, introduce deletion list

This commit is contained in:
Alexander Ivash 2018-10-22 23:29:39 +03:00
parent 5fef331995
commit 657ff7f6f8
3 changed files with 17 additions and 13 deletions

View file

@ -389,13 +389,9 @@ void OffscreenSurface::finishQmlLoad(QQmlComponent* qmlComponent,
}
// manually control children items lifetime
QQmlEngine::setObjectOwnership(newObject, QQmlEngine::CppOwnership);
// some objects we are going to delete might be already deleted (children of parent we already deleted) so use QPointer to track lifetime
QPointer<QObject> trackedObject(newObject);
connect(_sharedObject, &SharedObject::onBeforeDestroyed, [trackedObject]() {
if (trackedObject) {
delete trackedObject.data();
}
});
// add object to the manual deletion list
_sharedObject->addToDeletionList(newObject);
newObject->setParent(parent);
newItem->setParentItem(parent);

View file

@ -15,6 +15,7 @@
#include <QtQml/QQmlEngine>
#include <QtGui/QOpenGLContext>
#include <QPointer>
#include <NumericalConstants.h>
#include <shared/NsightHelpers.h>
@ -79,9 +80,6 @@ SharedObject::SharedObject() {
SharedObject::~SharedObject() {
emit onBeforeDestroyed();
// After destroy returns, the rendering thread should be gone
destroy();
// _renderTimer is created with `this` as the parent, so need no explicit destruction
@ -98,6 +96,11 @@ SharedObject::~SharedObject() {
}
#endif
// already deleted objects will be reset to null by QPointer so it should be safe just iterate here
for (auto qmlObject : _deletionList) {
delete qmlObject;
}
if (_rootItem) {
delete _rootItem;
_rootItem = nullptr;
@ -414,6 +417,11 @@ bool SharedObject::fetchTexture(TextureAndFence& textureAndFence) {
return true;
}
void hifi::qml::impl::SharedObject::addToDeletionList(QObject * object)
{
_deletionList.append(QPointer<QObject>(object));
}
void SharedObject::setProxyWindow(QWindow* window) {
#ifndef DISABLE_QML
_proxyWindow = window;

View file

@ -66,9 +66,7 @@ public:
void resume();
bool isPaused() const;
bool fetchTexture(TextureAndFence& textureAndFence);
signals:
void onBeforeDestroyed();
void addToDeletionList(QObject* object);
private:
bool event(QEvent* e) override;
@ -93,6 +91,8 @@ private:
void onAboutToQuit();
void updateTextureAndFence(const TextureAndFence& newTextureAndFence);
QList<QPointer<QObject>> _deletionList;
// Texture management
TextureAndFence _latestTextureAndFence{ 0, 0 };
QQuickItem* _item{ nullptr };