aboutsummaryrefslogtreecommitdiffstats
path: root/src/quick/scenegraph/qsgcontext.cpp
diff options
context:
space:
mode:
authorEskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io>2023-06-14 12:18:18 +0200
committerEskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io>2023-06-15 17:48:28 +0200
commiteed2ee69ac291da33c48093bc2c2bc4d359f46a2 (patch)
tree416a22c9cc01e2d3b6a495a6be94c673c4c73db0 /src/quick/scenegraph/qsgcontext.cpp
parent348eaf6b2abcff6ec3c835b706fb114ea80995e3 (diff)
Fix memory leak when invalidating NativeRendering fonts
When NativeRendering is used, we keep a reference to all the font engines currently in use to make sure they stay alive, and then dereference them when the scenegraph is invalidated, typically when the window closes. There was always a controlled leak here: If you loaded new font assets continuously, then we would retain the old ones in memory. Due to the bug in QTBUG-100697, we would keep them even if they were application fonts that were removed. However, when QTBUG-100697 was fixed, a side effect was that the memory leak became more visible: It no longer only happens when loading new fonts, but just loading and unloading the same two application fonts and setting them on a text item in a loop would cause us to continuously create new font engines, give them a font cache and then add them to the m_fontEnginesToClean list. The fix is to match the registerFontEngineToClean() with an unregister function and then clean up the font engines that no longer have any references during the synchronization step, similar to how we clean up distance field caches that are no longer in use. Note that this removes a bogus qDeleteAll() from the software backend: This was added blindly by f1b188df132c42da62197055725e5f7eebcc4249. Since the set will be empty, it doesn't cause a crash, but is not the correct way to delete font engines, so to avoid future confusion or cargo-culting, we just replace it with an assert that the set is empty. [ChangeLog][Text] Fixed a controlled memory leak with Text.NativeRendering where loading and unloading the same application fonts could cause memory usage to increase indefinitely and not be regained until the window was closed. Pick-to: 6.5 6.6 Fixes: QTBUG-113714 Change-Id: I34c60e647bf63a0d203f752066f1cbfaeb049bcf Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io> Reviewed-by: Andy Nichols <andy.nichols@qt.io>
Diffstat (limited to 'src/quick/scenegraph/qsgcontext.cpp')
-rw-r--r--src/quick/scenegraph/qsgcontext.cpp8
1 files changed, 7 insertions, 1 deletions
diff --git a/src/quick/scenegraph/qsgcontext.cpp b/src/quick/scenegraph/qsgcontext.cpp
index be7c934fd7..7668db7a69 100644
--- a/src/quick/scenegraph/qsgcontext.cpp
+++ b/src/quick/scenegraph/qsgcontext.cpp
@@ -475,7 +475,13 @@ void QSGRenderContext::invalidateGlyphCaches()
void QSGRenderContext::registerFontengineForCleanup(QFontEngine *engine)
{
engine->ref.ref();
- m_fontEnginesToClean << engine;
+ m_fontEnginesToClean[engine]++;
+}
+
+void QSGRenderContext::unregisterFontengineForCleanup(QFontEngine *engine)
+{
+ m_fontEnginesToClean[engine]--;
+ Q_ASSERT(m_fontEnginesToClean.value(engine) >= 0);
}
QRhi *QSGRenderContext::rhi() const