diff options
author | Bartlomiej Moskal <bartlomiej.moskal@qt.io> | 2024-01-15 10:31:36 +0100 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2024-01-16 08:24:39 +0000 |
commit | fd6c2ebcc1b0b449a861de64deed0ca019eb97b1 (patch) | |
tree | 9f297bd62d65db65cf1011d88b7cf0878efca457 | |
parent | 24f4aad3fdeb7aa1a751b552a2d6d8536cd2c260 (diff) |
QDice Example: Add a timer-guard for rolling dices
There is a problem in QQ3DPhysics. onBodyContact may still refer to
already deleted object - which causes the application to crash.
It happens when Accelerometer spam a lot with scene.spawnDice(...)
calls.
To avoid this crash, the timer-guard for rolling dices was added.
Pick-to: 6.6
Fixes: QTBUG-120364
Change-Id: I3ca3811662fb2400d61cb256c8b34885a6fe028a
Reviewed-by: Jonas Karlsson <jonas.karlsson@qt.io>
(cherry picked from commit ffc1984fd325deae4925cc638d9f32e03a517ad8)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r-- | examples/demos/dice/DiceSpawner.qml | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/examples/demos/dice/DiceSpawner.qml b/examples/demos/dice/DiceSpawner.qml index 4e8a991a9..9ccbb0b86 100644 --- a/examples/demos/dice/DiceSpawner.qml +++ b/examples/demos/dice/DiceSpawner.qml @@ -10,6 +10,7 @@ Node { id: shapeSpawner property var dices: [] property var dieComponent: Qt.createComponent("PhysicalDie.qml") + property bool justSpawned: false function randomInRange(min, max) { return Math.random() * (max - min) + min @@ -38,7 +39,8 @@ Node { source: "sounds/rolling.wav" } function spawnDice(numberOfDice, physicsMaterial, rollForce, diceWidth) { - if (allAtRest()) { + if (!justSpawned && allAtRest()) { + justSpawned = true; reset() rollSound.play() @@ -49,6 +51,18 @@ Node { index * 2.1, 0) createDie(initialPosition, physicsMaterial, rollForce, diceWidth) } + spawnTimer.start() + } + } + + Timer { + id: spawnTimer + interval: 500 + running: false + repeat: false + onRunningChanged: { + if (!running) + shapeSpawner.justSpawned = false } } |