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

Support limiting the memory taken by QSGGradientCache

    XMLWordPrintable

Details

    Description

      Background

      Gradients used in Qt Quick Shapes are cached unconditionally: https://github.com/qt/qtdeclarative/blob/v6.9.0/src/quick/scenegraph/util/qsggradientcache.cpp#L69-L118

       

      Problem

      Once a gradient texture enters the cache, it stays there quite permanently (well, at least it's deleted if the owning window is deleted, but this doesn't normally happen in embedded systems).

      In the example app below, dragging the slider will noticeably increase memory consumption (visible via the Windows Task Manager, for example), with no easy way to bring it down:

      import QtQuick
      import QtQuick.Shapes
      import QtQuick.Controls.Basic
      
      ApplicationWindow {
          id: root
          width: 640
          height: 480
          visible: true
      
          property real radius: 200
      
          header: Slider {
              id: hueSlider
              from: 0
              to: 1
          }
      
          Shape {
              x: root.radius
              y: root.radius
              width: root.radius * 2
              height: root.radius * 2
      
              ShapePath {
                  strokeWidth: 0
      
                  PathAngleArc {
                      radiusX: root.radius
                      radiusY: root.radius
                      startAngle: 0
                      sweepAngle: 360
                  }
                  fillGradient: ConicalGradient {
                      GradientStop { position: 0; color: "transparent" }
                      GradientStop { position: 0.5; color: Qt.hsva(hueSlider.value, 1, 1, 1) }
                      GradientStop { position: 1; color: "transparent" }
                  }
              }
          }
      }
      

       

      A customer's real app, which has animating gradients, crashed from running out of memory.

       

      Workarounds

      • Currently, we do have an API to clear the entire cache associated with a scene, e.g. quickWindow->rhi()->runCleanup();. However, this is a "nuclear" option that deletes all gradients (including those that are still needed), and it has to be done from C++.
      • Use the old Qt 5 Graphical Effects (e.g. https://doc.qt.io/qt-6/qml-qt5compat-graphicaleffects-conicalgradient.html ) which apply shader effects instead of cached textures.

       

      Suggestions

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            janichol Andy Nichols
            skoh-qt Sze Howe Koh
            Votes:
            6 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes