From 8a544f74ec60fccd565f204970d324a89d16d8d1 Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Sun, 13 Mar 2022 18:49:48 +0100 Subject: [PATCH] stats: make textures "global objects" These were leaking. Instead register them as global objects, so they will be deleted on exit. Signed-off-by: Berthold Stoeger --- stats/chartitem.cpp | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/stats/chartitem.cpp b/stats/chartitem.cpp index fb5a0d9ca..e3e2aeae4 100644 --- a/stats/chartitem.cpp +++ b/stats/chartitem.cpp @@ -2,6 +2,7 @@ #include "chartitem.h" #include "statscolors.h" #include "statsview.h" +#include "core/globals.h" #include #include @@ -136,10 +137,6 @@ static QSGTexture *createScatterTexture(StatsView &view, const QColor &color, co return view.w()->createTextureFromImage(img, QQuickWindow::TextureHasAlphaChannel); } -// Note: Originally these were std::unique_ptrs, which automatically -// freed the textures on exit. However, destroying textures after -// QApplication finished its thread leads to crashes. Therefore, these -// are now normal pointers and the texture objects are leaked. static QSGTexture *scatterItemTexture = nullptr; static QSGTexture *scatterItemSelectedTexture = nullptr; static QSGTexture *scatterItemHighlightedTexture = nullptr; @@ -161,9 +158,9 @@ QSGTexture *ChartScatterItem::getTexture() const void ChartScatterItem::render() { if (!scatterItemTexture) { - scatterItemTexture = createScatterTexture(view, fillColor, borderColor); - scatterItemSelectedTexture = createScatterTexture(view, selectedColor, selectedBorderColor); - scatterItemHighlightedTexture = createScatterTexture(view, highlightedColor, highlightedBorderColor); + scatterItemTexture = register_global(createScatterTexture(view, fillColor, borderColor)); + scatterItemSelectedTexture = register_global(createScatterTexture(view, selectedColor, selectedBorderColor)); + scatterItemHighlightedTexture = register_global(createScatterTexture(view, highlightedColor, highlightedBorderColor)); } if (!node) { createNode(view.w()->createImageNode()); @@ -437,7 +434,7 @@ QSGTexture *ChartBarItem::getSelectedTexture() const img.fill(Qt::transparent); img.setPixelColor(0, 0, selectionOverlayColor); img.setPixelColor(1, 1, selectionOverlayColor); - selectedTexture = view.w()->createTextureFromImage(img, QQuickWindow::TextureHasAlphaChannel); + selectedTexture = register_global(view.w()->createTextureFromImage(img, QQuickWindow::TextureHasAlphaChannel)); } return selectedTexture; }