mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
statistics: delete chart items when root node is deleted
When reparenting the statistics widget, QtQuick deletes the rootNode and all the child nodes. It is unclear whether this is a bug or intended behavior. In any case, it means that the pointers to QSG nodes in the chart items become stale. To avoid this, delete all chart items in the root node's destructor, before QtQuick can do anything. It is unclear from which context this is called (render or UI) and whether this is even valid. In some tests, it seemed to work. The difficulty is that all the stale pointers to chart items have to be deleted as well. All in all, the QSG memory management is a big nuisance and very brittle. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
805a2388af
commit
122092707c
2 changed files with 55 additions and 11 deletions
|
@ -43,13 +43,14 @@ public:
|
|||
~StatsView();
|
||||
|
||||
void plot(const StatsState &state);
|
||||
void updateFeatures(const StatsState &state); // Updates the visibility of chart features, such as legend, regression, etc.
|
||||
void updateFeatures(const StatsState &state); // Updates the visibility of chart features, such as legend, regression, etc.
|
||||
QQuickWindow *w() const; // Make window available to items
|
||||
QSizeF size() const;
|
||||
QRectF plotArea() const;
|
||||
void addQSGNode(QSGNode *node, ChartZValue z); // Must only be called in render thread!
|
||||
void registerChartItem(ChartItem &item);
|
||||
void registerDirtyChartItem(ChartItem &item);
|
||||
void emergencyShutdown(); // Called when QQuick decides to delete out root node.
|
||||
|
||||
// Create a chart item and add it to the scene.
|
||||
// The item must not be deleted by the caller, but can be
|
||||
|
@ -151,6 +152,10 @@ private:
|
|||
|
||||
// There are three double linked lists of chart items:
|
||||
// clean items, dirty items and items to be deleted.
|
||||
// Note that only the render thread must delete chart items,
|
||||
// and therefore these lists are the only owning pointers
|
||||
// to chart items. All other pointers are non-owning and
|
||||
// can therefore become stale.
|
||||
struct ChartItemList {
|
||||
ChartItemList();
|
||||
ChartItem *first, *last;
|
||||
|
@ -161,6 +166,7 @@ private:
|
|||
};
|
||||
ChartItemList cleanItems, dirtyItems, deletedItems;
|
||||
void deleteChartItemInternal(ChartItem &item);
|
||||
void freeDeletedChartItems();
|
||||
};
|
||||
|
||||
// This implementation detail must be known to users of the class.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue