From e32e6d63a7c158a03a851492f4f9d3edffe2f857 Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Tue, 19 Jan 2021 09:01:14 +0100 Subject: statistics: leak textures on exit The scatter plot items shared their textures. These were std::unique_ptrs and cleaned up on exit. Owing to QSG's broken memory model, freeing the textures after QApplication terminated its threads led to crashes. Therefore, leak the textures. Not satisfying, but ultimately harmless and better than a crash. Signed-off-by: Berthold Stoeger --- stats/chartitem.cpp | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/stats/chartitem.cpp b/stats/chartitem.cpp index 6a69b6973..7c5339596 100644 --- a/stats/chartitem.cpp +++ b/stats/chartitem.cpp @@ -117,7 +117,7 @@ ChartScatterItem::~ChartScatterItem() { } -static std::unique_ptr createScatterTexture(StatsView &view, const QColor &color, const QColor &borderColor) +static QSGTexture *createScatterTexture(StatsView &view, const QColor &color, const QColor &borderColor) { QImage img(scatterItemDiameter, scatterItemDiameter, QImage::Format_ARGB32); img.fill(Qt::transparent); @@ -130,13 +130,15 @@ static std::unique_ptr createScatterTexture(StatsView &view, const Q painter.drawEllipse(scatterItemBorder, scatterItemBorder, scatterItemDiameter - 2 * scatterItemBorder, scatterItemDiameter - 2 * scatterItemBorder); - return std::unique_ptr( - view.w()->createTextureFromImage(img, QQuickWindow::TextureHasAlphaChannel) - ); + return view.w()->createTextureFromImage(img, QQuickWindow::TextureHasAlphaChannel); } -std::unique_ptr scatterItemTexture; -std::unique_ptr scatterItemHighlightedTexture; +// 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 *scatterItemHighlightedTexture = nullptr; void ChartScatterItem::render() { @@ -151,7 +153,7 @@ void ChartScatterItem::render() } updateVisible(); if (textureDirty) { - node->node->setTexture(highlighted ? scatterItemHighlightedTexture.get() : scatterItemTexture.get()); + node->node->setTexture(highlighted ? scatterItemHighlightedTexture : scatterItemTexture); textureDirty = false; } if (positionDirty) { -- cgit v1.2.3-70-g09d2