diff options
author | Paul Lemire <paul.lemire@kdab.com> | 2016-12-16 09:59:54 +0100 |
---|---|---|
committer | Jani Heikkinen <jani.heikkinen@qt.io> | 2016-12-16 10:08:31 +0000 |
commit | 170f5a89b59f3489267aaede36d7728f90b2e114 (patch) | |
tree | 3c2cf812ceb7b54c1175074c6eaa91701d393a1e | |
parent | d4e062abfa98285c581c55f42fec590a3815c95f (diff) |
Only pass static metaobjects around and fix EntityLoader
- Ensure the notification changes only pass in static metaobjects.
- Make the EntityLoader use the AsynchronousIfNested incubation mode to avoid
cases where we could destroy something still being incubated
- Add a manual test to test this cases
This fixes the crashes occurring when using NodeInstantiators and EntityLoaders
as delegates.
Change-Id: I104c60b4be34cfb843a74dd09a8b96fdac44657d
Task-number: QTBUG-57655
Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
-rw-r--r-- | src/core/changes/qcomponentaddedchange.cpp | 3 | ||||
-rw-r--r-- | src/core/changes/qcomponentremovedchange.cpp | 3 | ||||
-rw-r--r-- | src/core/changes/qpropertynodeaddedchange.cpp | 2 | ||||
-rw-r--r-- | src/quick3d/quick3d/items/quick3dentityloader.cpp | 8 | ||||
-rw-r--r-- | src/quick3d/quick3d/items/quick3dentityloader_p.h | 1 | ||||
-rw-r--r-- | tests/manual/dynamic-model-loader-qml/CuboidEntity.qml | 97 | ||||
-rw-r--r-- | tests/manual/dynamic-model-loader-qml/SphereEntity.qml | 89 | ||||
-rw-r--r-- | tests/manual/dynamic-model-loader-qml/dynamic-model-loader-qml.pro | 16 | ||||
-rw-r--r-- | tests/manual/dynamic-model-loader-qml/dynamic-model-loader-qml.qrc | 7 | ||||
-rw-r--r-- | tests/manual/dynamic-model-loader-qml/main.cpp | 63 | ||||
-rw-r--r-- | tests/manual/dynamic-model-loader-qml/main.qml | 140 | ||||
-rw-r--r-- | tests/manual/manual.pro | 3 |
12 files changed, 427 insertions, 5 deletions
diff --git a/src/core/changes/qcomponentaddedchange.cpp b/src/core/changes/qcomponentaddedchange.cpp index 1ad25651b..93e277a58 100644 --- a/src/core/changes/qcomponentaddedchange.cpp +++ b/src/core/changes/qcomponentaddedchange.cpp @@ -41,6 +41,7 @@ #include "qcomponentaddedchange_p.h" #include <Qt3DCore/qcomponent.h> #include <Qt3DCore/qentity.h> +#include <private/qnode_p.h> QT_BEGIN_NAMESPACE @@ -51,7 +52,7 @@ QComponentAddedChangePrivate::QComponentAddedChangePrivate(const QEntity *entity : QSceneChangePrivate() , m_entityId(entity->id()) , m_componentId(component->id()) - , m_componentMetaObject(component->metaObject()) + , m_componentMetaObject(QNodePrivate::findStaticMetaObject(component->metaObject())) { } diff --git a/src/core/changes/qcomponentremovedchange.cpp b/src/core/changes/qcomponentremovedchange.cpp index e1625ac93..e0a940781 100644 --- a/src/core/changes/qcomponentremovedchange.cpp +++ b/src/core/changes/qcomponentremovedchange.cpp @@ -41,6 +41,7 @@ #include "qcomponentremovedchange_p.h" #include <Qt3DCore/qcomponent.h> #include <Qt3DCore/qentity.h> +#include <private/qnode_p.h> QT_BEGIN_NAMESPACE @@ -51,7 +52,7 @@ QComponentRemovedChangePrivate::QComponentRemovedChangePrivate(const QEntity *en : QSceneChangePrivate() , m_entityId(entity->id()) , m_componentId(component->id()) - , m_componentMetaObject(component->metaObject()) + , m_componentMetaObject(QNodePrivate::findStaticMetaObject(component->metaObject())) { } diff --git a/src/core/changes/qpropertynodeaddedchange.cpp b/src/core/changes/qpropertynodeaddedchange.cpp index 539c6a54a..c2eafe827 100644 --- a/src/core/changes/qpropertynodeaddedchange.cpp +++ b/src/core/changes/qpropertynodeaddedchange.cpp @@ -73,7 +73,7 @@ QPropertyNodeAddedChange::QPropertyNodeAddedChange(QNodeId subjectId, QNode *nod : QStaticPropertyValueAddedChangeBase(*new QPropertyNodeAddedChangePrivate, subjectId) { Q_D(QPropertyNodeAddedChange); - d->m_addedNodeIdTypePair = QNodeIdTypePair(node->id(), node->metaObject()); + d->m_addedNodeIdTypePair = QNodeIdTypePair(node->id(), QNodePrivate::findStaticMetaObject(node->metaObject())); } /*! \internal */ diff --git a/src/quick3d/quick3d/items/quick3dentityloader.cpp b/src/quick3d/quick3d/items/quick3dentityloader.cpp index 63f4cceac..9f305d977 100644 --- a/src/quick3d/quick3d/items/quick3dentityloader.cpp +++ b/src/quick3d/quick3d/items/quick3dentityloader.cpp @@ -54,7 +54,7 @@ class Quick3DEntityLoaderIncubator : public QQmlIncubator { public: Quick3DEntityLoaderIncubator(Quick3DEntityLoader *loader) - : QQmlIncubator(Asynchronous), + : QQmlIncubator(AsynchronousIfNested), m_loader(loader) { } @@ -100,6 +100,12 @@ Quick3DEntityLoader::Quick3DEntityLoader(QNode *parent) { } +Quick3DEntityLoader::~Quick3DEntityLoader() +{ + Q_D(Quick3DEntityLoader); + d->clear(); +} + /*! \qmlproperty QtQml::QtObject Qt3DCore::EntityLoader::entity \readonly diff --git a/src/quick3d/quick3d/items/quick3dentityloader_p.h b/src/quick3d/quick3d/items/quick3dentityloader_p.h index 928f31ada..5721af115 100644 --- a/src/quick3d/quick3d/items/quick3dentityloader_p.h +++ b/src/quick3d/quick3d/items/quick3dentityloader_p.h @@ -76,6 +76,7 @@ class QT3DQUICKSHARED_PRIVATE_EXPORT Quick3DEntityLoader : public QEntity Q_PROPERTY(QUrl source READ source WRITE setSource NOTIFY sourceChanged) public: explicit Quick3DEntityLoader(QNode *parent = 0); + ~Quick3DEntityLoader(); QObject *entity() const; diff --git a/tests/manual/dynamic-model-loader-qml/CuboidEntity.qml b/tests/manual/dynamic-model-loader-qml/CuboidEntity.qml new file mode 100644 index 000000000..8555b6903 --- /dev/null +++ b/tests/manual/dynamic-model-loader-qml/CuboidEntity.qml @@ -0,0 +1,97 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB). +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Qt3D module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.4 as QQ2 +import Qt3D.Core 2.0 +import Qt3D.Render 2.0 +import Qt3D.Extras 2.0 + +Entity { + components: [ mesh, phongMaterial, transform ] + + CuboidMesh { + id: mesh + yzMeshResolution: Qt.size(2, 2) + xzMeshResolution: Qt.size(2, 2) + xyMeshResolution: Qt.size(2, 2) + } + + GoochMaterial { + id: phongMaterial + } + + Transform { + id: transform + property real userAngle: 0.0 + scale: 4 + rotation: fromAxisAndAngle(Qt.vector3d(0, 1, 0), userAngle) + } + + QQ2.ColorAnimation { + target: phongMaterial + property: "warmColor" + from: "red" + to: "blue" + duration: 2500 + loops: QQ2.Animation.Infinite + running: true + } + + QQ2.NumberAnimation { + target: transform + property: "userAngle" + duration: 750 + loops: QQ2.Animation.Infinite + running: true + easing.type: QQ2.Easing.InOutQuad + from: 0 + to: 360 + } +} diff --git a/tests/manual/dynamic-model-loader-qml/SphereEntity.qml b/tests/manual/dynamic-model-loader-qml/SphereEntity.qml new file mode 100644 index 000000000..8e11de99e --- /dev/null +++ b/tests/manual/dynamic-model-loader-qml/SphereEntity.qml @@ -0,0 +1,89 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB). +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Qt3D module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.4 as QQ2 +import Qt3D.Core 2.0 +import Qt3D.Render 2.0 +import Qt3D.Extras 2.0 + +Entity { + components: [ mesh, material, transform ] + + SphereMesh { + id: mesh + radius: 3 + } + + Transform { + id: transform + scale: 3 + } + + QQ2.ColorAnimation { + target: material + property: "diffuse" + from: "yellow" + to: "orange" + duration: 1500 + loops: QQ2.Animation.Infinite + running: true + } + + QQ2.NumberAnimation { + target: transform + property: "scale" + duration: 1500 + loops: QQ2.Animation.Infinite + running: true + easing.type: QQ2.Easing.InOutQuad + from: 1 + to: 1.5 + } +} diff --git a/tests/manual/dynamic-model-loader-qml/dynamic-model-loader-qml.pro b/tests/manual/dynamic-model-loader-qml/dynamic-model-loader-qml.pro new file mode 100644 index 000000000..b19091873 --- /dev/null +++ b/tests/manual/dynamic-model-loader-qml/dynamic-model-loader-qml.pro @@ -0,0 +1,16 @@ +!include( ../manual.pri ) { + error( "Couldn't find the manual.pri file!" ) +} + +QT += 3dcore 3drender 3dinput 3dquick qml quick 3dquickextras + +SOURCES += \ + main.cpp + +OTHER_FILES += \ + main.qml \ + SphereEntity.qml \ + CuboidEntity.qml + +RESOURCES += \ + dynamic-model-loader-qml.qrc diff --git a/tests/manual/dynamic-model-loader-qml/dynamic-model-loader-qml.qrc b/tests/manual/dynamic-model-loader-qml/dynamic-model-loader-qml.qrc new file mode 100644 index 000000000..8cf177b62 --- /dev/null +++ b/tests/manual/dynamic-model-loader-qml/dynamic-model-loader-qml.qrc @@ -0,0 +1,7 @@ +<RCC> + <qresource prefix="/"> + <file>main.qml</file> + <file>SphereEntity.qml</file> + <file>CuboidEntity.qml</file> + </qresource> +</RCC> diff --git a/tests/manual/dynamic-model-loader-qml/main.cpp b/tests/manual/dynamic-model-loader-qml/main.cpp new file mode 100644 index 000000000..a75e1d141 --- /dev/null +++ b/tests/manual/dynamic-model-loader-qml/main.cpp @@ -0,0 +1,63 @@ +/**************************************************************************** +** +** Copyright (C) 2016 Klaralvdalens Datakonsult AB (KDAB). +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Qt3D module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <Qt3DQuickExtras/qt3dquickwindow.h> +#include <QGuiApplication> + +int main(int argc, char* argv[]) +{ + QGuiApplication app(argc, argv); + Qt3DExtras::Quick::Qt3DQuickWindow view; + + view.setSource(QUrl("qrc:/main.qml")); + view.show(); + + return app.exec(); +} diff --git a/tests/manual/dynamic-model-loader-qml/main.qml b/tests/manual/dynamic-model-loader-qml/main.qml new file mode 100644 index 000000000..72d0529b8 --- /dev/null +++ b/tests/manual/dynamic-model-loader-qml/main.qml @@ -0,0 +1,140 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB). +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Qt3D module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.2 as QQ2 +import Qt3D.Core 2.0 +import Qt3D.Render 2.0 +import Qt3D.Input 2.0 +import Qt3D.Extras 2.0 + +Entity { + id: sceneRoot + + Camera { + id: camera + projectionType: CameraLens.PerspectiveProjection + fieldOfView: 45 + aspectRatio: 16/9 + nearPlane : 0.1 + farPlane : 1000.0 + position: Qt.vector3d( 0.0, 0.0, 40.0 ) + upVector: Qt.vector3d( 0.0, 1.0, 0.0 ) + viewCenter: Qt.vector3d( 0.0, 0.0, 0.0 ) + } + + OrbitCameraController { camera: camera } + + components: [ + RenderSettings { + activeFrameGraph: ForwardRenderer { + camera: camera + } + }, + // Event Source will be set by the Qt3DQuickWindow + InputSettings { } + ] + + + PhongMaterial { + id: material + diffuse: "yellow" + } + + TorusMesh { + id: torusMesh + radius: 5 + minorRadius: 1 + rings: 100 + slices: 20 + } + + Transform { + id: torusTransform + scale3D: Qt.vector3d(1.5, 1, 0.5) + rotation: fromAxisAndAngle(Qt.vector3d(1, 0, 0), 45) + } + + Entity { + id: torusEntity + components: [ torusMesh, material, torusTransform ] + } + + QQ2.Timer { + interval: 1000 + running: true + repeat: true + property bool addMore: true + + onTriggered: { + if (instantiator.model > 10 || instantiator.model < 2) + addMore = !addMore + instantiator.model += (addMore ? 1 : -1) + } + } + + NodeInstantiator { + id: instantiator + model: 2 + readonly property real angleStep: 360.0 / Math.max(count, 1) + EntityLoader { + components: Transform { + id: revolutionTransform + matrix: { + var m = Qt.matrix4x4(); + m.rotate(model.index * instantiator.angleStep, Qt.vector3d(0, 1, 0)); + m.translate(Qt.vector3d(20, 0, 0)); + return m; + } + } + source: model.index % 2 === 0 ? "qrc:/CuboidEntity.qml" : "qrc:/SphereEntity.qml" + } + + } +} diff --git a/tests/manual/manual.pro b/tests/manual/manual.pro index 5a10e4e0f..bfb95bfc2 100644 --- a/tests/manual/manual.pro +++ b/tests/manual/manual.pro @@ -33,7 +33,8 @@ SUBDIRS += \ transparency-qml \ transparency-qml-scene3d \ rendercapture-qml \ - additional-attributes-qml + additional-attributes-qml \ + dynamic-model-loader-qml qtHaveModule(widgets): { SUBDIRS += \ |