1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
|
// Copyright (C) 2024 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
// Tests that removing and adding objects with active contact callbacks
// does not crash. QTBUG-121033
import QtCore
import QtTest
import QtQuick3D
import QtQuick3D.Physics
import QtQuick3D.Physics.Helpers
import QtQuick
Item {
width: 800
height: 600
visible: true
PhysicsWorld {
scene: viewport.scene
}
View3D {
id: viewport
width: parent.width
height: parent.height
focus: true
environment: SceneEnvironment {
antialiasingMode: SceneEnvironment.MSAA
backgroundMode: SceneEnvironment.Color
clearColor: "#f0f0f0"
}
PerspectiveCamera {
id: camera
position: Qt.vector3d(-400, 500, 1000)
eulerRotation: Qt.vector3d(-20, -20, 0)
clipFar: 5000
clipNear: 1
}
DirectionalLight {
eulerRotation: Qt.vector3d(-45, 45, 0)
}
Node {
id: shapeSpawner
property var instancesBoxes: []
property var boxComponent: Qt.createComponent("Box.qml")
property int numSpawns: 0
function createStack() {
let size = 10
for (var i = 0; i < 3; i++) {
for (var j = 0; j < 3; j++) {
let center = Qt.vector3d(j*100, 100*i, 0)
let box = boxComponent.incubateObject(shapeSpawner, {
"position": center,
})
instancesBoxes.push(box)
}
}
numSpawns = numSpawns + 1;
}
function reset() {
// Only run method if previous stack has been created fully
for (var i = 0; i < instancesBoxes.length; i++)
if (!instancesBoxes[i].object)
return
instancesBoxes.forEach(box => {
box.object.collisionShapes = []
box.object.destroy()
})
instancesBoxes = []
shapeSpawner.createStack()
}
}
}
FrameAnimation {
property int frame: 0
running: true
onTriggered: {
frame = frame + 1;
if (frame % 2 == 0) {
shapeSpawner.reset()
}
}
}
TestCase {
name: "100 cycles"
when: shapeSpawner.numSpawns > 100
function triggered() {}
}
}
|