mirror of
https://github.com/overte-org/overte.git
synced 2025-08-04 04:23:33 +02:00
eliminate signal, introduce deletion list
This commit is contained in:
parent
5fef331995
commit
657ff7f6f8
3 changed files with 17 additions and 13 deletions
|
@ -389,13 +389,9 @@ void OffscreenSurface::finishQmlLoad(QQmlComponent* qmlComponent,
|
||||||
}
|
}
|
||||||
// manually control children items lifetime
|
// manually control children items lifetime
|
||||||
QQmlEngine::setObjectOwnership(newObject, QQmlEngine::CppOwnership);
|
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);
|
// add object to the manual deletion list
|
||||||
connect(_sharedObject, &SharedObject::onBeforeDestroyed, [trackedObject]() {
|
_sharedObject->addToDeletionList(newObject);
|
||||||
if (trackedObject) {
|
|
||||||
delete trackedObject.data();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
newObject->setParent(parent);
|
newObject->setParent(parent);
|
||||||
newItem->setParentItem(parent);
|
newItem->setParentItem(parent);
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
#include <QtQml/QQmlEngine>
|
#include <QtQml/QQmlEngine>
|
||||||
|
|
||||||
#include <QtGui/QOpenGLContext>
|
#include <QtGui/QOpenGLContext>
|
||||||
|
#include <QPointer>
|
||||||
|
|
||||||
#include <NumericalConstants.h>
|
#include <NumericalConstants.h>
|
||||||
#include <shared/NsightHelpers.h>
|
#include <shared/NsightHelpers.h>
|
||||||
|
@ -79,9 +80,6 @@ SharedObject::SharedObject() {
|
||||||
|
|
||||||
|
|
||||||
SharedObject::~SharedObject() {
|
SharedObject::~SharedObject() {
|
||||||
|
|
||||||
emit onBeforeDestroyed();
|
|
||||||
|
|
||||||
// After destroy returns, the rendering thread should be gone
|
// After destroy returns, the rendering thread should be gone
|
||||||
destroy();
|
destroy();
|
||||||
// _renderTimer is created with `this` as the parent, so need no explicit destruction
|
// _renderTimer is created with `this` as the parent, so need no explicit destruction
|
||||||
|
@ -98,6 +96,11 @@ SharedObject::~SharedObject() {
|
||||||
}
|
}
|
||||||
#endif
|
#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) {
|
if (_rootItem) {
|
||||||
delete _rootItem;
|
delete _rootItem;
|
||||||
_rootItem = nullptr;
|
_rootItem = nullptr;
|
||||||
|
@ -414,6 +417,11 @@ bool SharedObject::fetchTexture(TextureAndFence& textureAndFence) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void hifi::qml::impl::SharedObject::addToDeletionList(QObject * object)
|
||||||
|
{
|
||||||
|
_deletionList.append(QPointer<QObject>(object));
|
||||||
|
}
|
||||||
|
|
||||||
void SharedObject::setProxyWindow(QWindow* window) {
|
void SharedObject::setProxyWindow(QWindow* window) {
|
||||||
#ifndef DISABLE_QML
|
#ifndef DISABLE_QML
|
||||||
_proxyWindow = window;
|
_proxyWindow = window;
|
||||||
|
|
|
@ -66,9 +66,7 @@ public:
|
||||||
void resume();
|
void resume();
|
||||||
bool isPaused() const;
|
bool isPaused() const;
|
||||||
bool fetchTexture(TextureAndFence& textureAndFence);
|
bool fetchTexture(TextureAndFence& textureAndFence);
|
||||||
|
void addToDeletionList(QObject* object);
|
||||||
signals:
|
|
||||||
void onBeforeDestroyed();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool event(QEvent* e) override;
|
bool event(QEvent* e) override;
|
||||||
|
@ -93,6 +91,8 @@ private:
|
||||||
void onAboutToQuit();
|
void onAboutToQuit();
|
||||||
void updateTextureAndFence(const TextureAndFence& newTextureAndFence);
|
void updateTextureAndFence(const TextureAndFence& newTextureAndFence);
|
||||||
|
|
||||||
|
QList<QPointer<QObject>> _deletionList;
|
||||||
|
|
||||||
// Texture management
|
// Texture management
|
||||||
TextureAndFence _latestTextureAndFence{ 0, 0 };
|
TextureAndFence _latestTextureAndFence{ 0, 0 };
|
||||||
QQuickItem* _item{ nullptr };
|
QQuickItem* _item{ nullptr };
|
||||||
|
|
Loading…
Reference in a new issue