Details
Description
When deleting and creating instance tables, sometimes a model will be shown with the wrong instance data. This happens because QtQuick3D will reuse old GPU data if the scenegraph node happens to have the same address as a previously created instance table node.
This can be reproduced with the following code
import QtQuick import QtQuick3D import QtQuick.ControlsWindow { width: 640 height: 480 visible: true title: qsTr("InstanceLoader") View3D { id: view3D anchors.fill: parent environment: sceneEnvironment SceneEnvironment { id: sceneEnvironment clearColor: "#ffe0e0e0" backgroundMode: SceneEnvironment.Color antialiasingMode: SceneEnvironment.MSAA antialiasingQuality: SceneEnvironment.High } Node { id: scene DirectionalLight { id: directionalLight eulerRotation.z: 0.00003 eulerRotation.y: 0 eulerRotation.x: -61 brightness: 1 } PerspectiveCamera { id: cameraPerspective clipNear: 0.1 fieldOfView: 60 y:1.5 z: 5 } Component { id: cube Model { InstanceList { id: manualInstancing1 instances: [ InstanceListEntry { position: Qt.vector3d(0, 0, 0) eulerRotation: Qt.vector3d(0, 60, 0) color: "#00ffff" }, InstanceListEntry { position: Qt.vector3d(1, 0, 0) eulerRotation: Qt.vector3d(0, 60, 0) color: "#ff00ff" }, InstanceListEntry { position: Qt.vector3d(-1, 0, 0) eulerRotation: Qt.vector3d(0, 60, 0) color: "#ff9900" } ] } source: "#Cube" scale: "0.01, 0.01, 0.01" instancing: manualInstancing1 materials: DefaultMaterial { diffuseColor: "white" } } } Component { id: cylinder Model { InstanceList { id: manualInstancing2 instances: [ InstanceListEntry { position: Qt.vector3d(0, 0, 0) eulerRotation: Qt.vector3d(0, 20, 0) color: "#ffffff" }, InstanceListEntry { position: Qt.vector3d(1.5, 0, 0) eulerRotation: Qt.vector3d(0, 20, 0) scale: "2,2,2" color: "#ffff77" }, InstanceListEntry { position: Qt.vector3d(-1, 0, 0) eulerRotation: Qt.vector3d(0, 20, 0) color: "#ffcccc" } ] } source: "#Cylinder" scale: "0.01, 0.01, 0.01" instancing: manualInstancing2 materials: DefaultMaterial { diffuseColor: "white" } } } Loader3D { id: loader3D property int currentIndex: 0 sourceComponent: currentIndex === 0 ? cube : cylinder NumberAnimation on currentIndex { from: 0 to: 1 loops: -1 duration: 1500 } } } } }