Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Animation on y seems to interfere with onYChanged signal / x manipulation

Animation on y seems to interfere with onYChanged signal / x manipulation

Scheduled Pinned Locked Moved Solved QML and Qt Quick
5 Posts 3 Posters 843 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • SeDiS Offline
    SeDiS Offline
    SeDi
    wrote on last edited by SeDi
    #1

    Hi,
    I am experiencing frequent (but not 100% reproducible, more like 30%-40%) crashs when I try to add a speed- and random-based x-movement to my linear y-animation.

    I am trying to achieve a "falling glitter"-effect. I have a Repeater, that produces a number of little stars. Each star is a Canvas QML type. Here's what I do:

            Canvas {
                z:1
                id: rootCanvas
                width: 20
                height: 28
                visible: solvedRepeater.contentVisible
                property real startY: 0
                property real xSpeed: 0
    
                onVisibleChanged: {
                    if (visible) {
                        rootCanvas.x =   Math.random()*appWindow.width
                        rootCanvas.y = (1.5 * Math.random()*appWindow.height) - appWindow.height
                        rootCanvas.rotation = Math.random()*360
                        startY = y
                        parallelAnimationSolved.restart()
                    }
                }
                ParallelAnimation {
                    id: parallelAnimationSolved
                    running: false
                    NumberAnimation {
                        target: rootCanvas
                        property: "y"
                        to: 2 * appWindow.height+startY;
                        duration: 3000 + (Math.random()*1000 - 500) // different tempos
                        running: false
                    }
                    RotationAnimation {
                        direction: RotationAnimation.Clockwise
                        target: rootCanvas
                        to: 360*Math.random() * 7;
                        running: false;
                        duration: yNumberAnimation.duration
                    }
                }
                onYChanged: {
                    xSpeed += Math.random()*.4 - .2
                    x += xSpeed;
                }
    
                onPaint: {
                    var ctx = getContext("2d")
                    ctx.clearRect(0,0,width,height)
                    ctx.lineWidth = 1
                    ctx.strokeStyle = "gold"
                    ctx.beginPath()
    
                    ctx.moveTo(height*23/100,width*18/100)
                    ctx.lineTo(height*40/100,width*28/100)
                    // [...]  many more "lineTo"s...
                    ctx.closePath()
    
                    ctx.fillStyle = "gold" 
                    ctx.fill()
                    ctx.stroke();
                }
            }
        }
    }
    

    The code doesn't seem to crash, as long as I out-comment the onYChanged: {…} part.

    I've had experienced such crashes even more often, when both parts of the ParallelAnimation were independent NumberAnimations. After putting both in the ParallelAnimation it improved, but the problem persists as long as the onYChanged-section is not commented out.

    I haven't found anything in the docs about not being allowed to touch the animated property for reading or to alter a different property - and I have no idea how to implement a dynamic and random-driven xSpeed within a QML Animation (that ultimately could be put in the ParallelAnimation).

    Any ideas what I can do?
    [Qt5.11.2, crashes happen on Windows and Android]

    1 Reply Last reply
    0
    • dheerendraD Offline
      dheerendraD Offline
      dheerendra
      Qt Champions 2022
      wrote on last edited by
      #2

      Not sure why it crashes. How about adding the animation for x with same duration as y. Do you have small sample which we can see and suggest ?

      Dheerendra
      @Community Service
      Certified Qt Specialist
      http://www.pthinks.com

      SeDiS 1 Reply Last reply
      1
      • GrecKoG Offline
        GrecKoG Offline
        GrecKo
        Qt Champions 2018
        wrote on last edited by
        #3

        This might interest you : http://doc.qt.io/qt-5/qtquick-effects-particles.html

        SeDiS 1 Reply Last reply
        1
        • dheerendraD dheerendra

          Not sure why it crashes. How about adding the animation for x with same duration as y. Do you have small sample which we can see and suggest ?

          SeDiS Offline
          SeDiS Offline
          SeDi
          wrote on last edited by SeDi
          #4

          @dheerendra : Thank you very much for your help. I would have thought to hit a limitation of some kind, but when you didn't see a problem in the code I tried to look for different reasons for the crash, and it seems I have found one:

          The use of the animation seems to have revealed a previously undiscovered ownership problem that I've probably had - or at least have made it more probable to surface and crash the application.

          Since I've added the "setObjectOwnership" line below, the crash didn't (yet) occur again:

          void *QmlGenerator::createEmptyEquation(QQuickItem *loader) {
              loader->setProperty("sourceComponent",  QVariant());
              m_engine->setObjectOwnership(loader, QQmlEngine::CppOwnership);    //[Edit: correction]
          }
          

          I am still not 100% sure to have found the actual bug, but as I meanwhile did encounter the very same crash without any animation (only once, but it was there), I am quite sure that this question can be closed.

          [Edit for posterity: Since I have taken ownership to Cpp and carefully check which Object I need to ->deleteLater() the bug is gone. Yeeha.]

          Thank you very much again - your answer brought me to doubt my (false) assumtpion.

          1 Reply Last reply
          0
          • GrecKoG GrecKo

            This might interest you : http://doc.qt.io/qt-5/qtquick-effects-particles.html

            SeDiS Offline
            SeDiS Offline
            SeDi
            wrote on last edited by
            #5

            @GrecKo Thank you, that does indeed look very interesting. I will dig into that, regardless of this (probably solved) case.

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved