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 <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2022-03-13 18:49:48 +01:00 committed by Dirk Hohndel
parent ee9344eccf
commit 8a544f74ec

View file

@ -2,6 +2,7 @@
#include "chartitem.h" #include "chartitem.h"
#include "statscolors.h" #include "statscolors.h"
#include "statsview.h" #include "statsview.h"
#include "core/globals.h"
#include <cmath> #include <cmath>
#include <QQuickWindow> #include <QQuickWindow>
@ -136,10 +137,6 @@ static QSGTexture *createScatterTexture(StatsView &view, const QColor &color, co
return view.w()->createTextureFromImage(img, QQuickWindow::TextureHasAlphaChannel); 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 *scatterItemTexture = nullptr;
static QSGTexture *scatterItemSelectedTexture = nullptr; static QSGTexture *scatterItemSelectedTexture = nullptr;
static QSGTexture *scatterItemHighlightedTexture = nullptr; static QSGTexture *scatterItemHighlightedTexture = nullptr;
@ -161,9 +158,9 @@ QSGTexture *ChartScatterItem::getTexture() const
void ChartScatterItem::render() void ChartScatterItem::render()
{ {
if (!scatterItemTexture) { if (!scatterItemTexture) {
scatterItemTexture = createScatterTexture(view, fillColor, borderColor); scatterItemTexture = register_global(createScatterTexture(view, fillColor, borderColor));
scatterItemSelectedTexture = createScatterTexture(view, selectedColor, selectedBorderColor); scatterItemSelectedTexture = register_global(createScatterTexture(view, selectedColor, selectedBorderColor));
scatterItemHighlightedTexture = createScatterTexture(view, highlightedColor, highlightedBorderColor); scatterItemHighlightedTexture = register_global(createScatterTexture(view, highlightedColor, highlightedBorderColor));
} }
if (!node) { if (!node) {
createNode(view.w()->createImageNode()); createNode(view.w()->createImageNode());
@ -437,7 +434,7 @@ QSGTexture *ChartBarItem::getSelectedTexture() const
img.fill(Qt::transparent); img.fill(Qt::transparent);
img.setPixelColor(0, 0, selectionOverlayColor); img.setPixelColor(0, 0, selectionOverlayColor);
img.setPixelColor(1, 1, selectionOverlayColor); img.setPixelColor(1, 1, selectionOverlayColor);
selectedTexture = view.w()->createTextureFromImage(img, QQuickWindow::TextureHasAlphaChannel); selectedTexture = register_global(view.w()->createTextureFromImage(img, QQuickWindow::TextureHasAlphaChannel));
} }
return selectedTexture; return selectedTexture;
} }