Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-139306

Popup inside an async Loader crashes Qt Quick app if there is direct property binding (possible racing condition)

XMLWordPrintable

    • 8d1a8c183 (dev), 39511014e (6.10), 7e59a4945 (6.9), 55ebad523 (6.9), 1e302b9d1 (dev), 7483de1f5 (tqtc/lts-6.8), 2f76b2f14 (6.10)

      Reproducer attached. Build and run and it crashes fairly quickly. The exact duration is random, but it definitely crashes after a few seconds.

      Basic context:
      Repeater is going to show a series of Loader instances at random locations. Loader also gets invalidated randomly (see the observations). The logic of "randomness" is from C++ side. QAbstractlistModel provides model to Repeater and data type is custom QObject that exposes "x" and "y" coordinates.

      Some observations:
      1. Loader is async. Changing "asynchronous: true" to "asynchronous: false" solves the problem.
      2. Loader randomly (and quite frequently) destroys its sourceComponent because this line:

      active: delegateRoot.pointObject.x % 2 == 1 || delegateRoot.pointObject.y % 2 == 1
      

      "pointObject" is the model data passed from C++ side which contains "x" and "y" coordinate. And those coordinates keep changing based on the interval of QTimer. See inside "pointsmodel.cpp":

      connect(&m_timer, &QTimer::timeout, this, &PointsModel::updateRandomPoints);
      

      If one comment out the binding to "active", i.e. Loader is always active, then app stop crashing.
      3. Speaking of the C++ logic in #2, one can use a longer interval for QTimer, e.g. m_timer.start(100); or something, then the application can last longer before it crashes.
      4. Avoiding direct property binding can also stop crashing. One can comment out

      visible: dragWrapper.enabled
      

      in main.qml and uncomment

      onEnabledChanged: shader.visible = dragWrapper.enabled
      

      Assignment and property binding have the same logic, but assignment does not crash the app.
      5. Popup seems to be special. If one replaces it with, e.g. Button, then app does not crash.
      6. The direct access to the property that is being monitored seems to be a problem too. If one comment out

      shader.visible
      

      , that is, do not touch "visible" inside "onVisibleChanged", then app does not crash. One can do anything inside "onVisibleChanged" without crashing the app - except touching "visible" in any form.

      It partially feels like a racing condition, including the fact that "sync Loader solves the problem", "long-living sourceComponent solves the problem", "less frequent destruction alleviates the problem". But "Popup-specific" and "accessing property issue" feel strange to me.

        For Gerrit Dashboard: QTBUG-139306
        # Subject Branch Project Status CR V

            mitch_curtis Mitch Curtis
            luqiaochen Luqiao Chen
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated:
              Resolved: