mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
statistics: refactor QSG memory management
The code was wrong, because it deleted the ChartItems in the main UI thread, not the render thread. This would delete the QSG nodes in the UI thread and then crash on mobile. Therefore refactor this part of the code by adding the items to be deleted to a list that will be deleted by the render thread. As a drop in replacement of std::unique_ptr, implement a silly ChartItemPtr class, which auto-initializes to null. This turns the deterministic and easily controlled memory management into a steaming pile of insanity. Obviously, this can be made much more elegant, but this has to do for now. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
9d3de1801e
commit
db69c38245
17 changed files with 245 additions and 88 deletions
|
@ -7,6 +7,52 @@
|
|||
#include <memory>
|
||||
#include <QSGNode>
|
||||
|
||||
// A stupid pointer class that initializes to null and can be copy
|
||||
// assigned. This is for historical reasons: unique_ptrs to ChartItems
|
||||
// were replaced by plain pointers. Instead of nulling the plain pointers
|
||||
// in the constructors, use this. Ultimately, we might think about making
|
||||
// this thing smarter, once removal of individual ChartItems is implemented.
|
||||
template <typename T>
|
||||
class ChartItemPtr {
|
||||
friend class StatsView; // Only the stats view can create these pointers
|
||||
T *ptr;
|
||||
ChartItemPtr(T *ptr) : ptr(ptr)
|
||||
{
|
||||
}
|
||||
public:
|
||||
ChartItemPtr() : ptr(nullptr)
|
||||
{
|
||||
}
|
||||
ChartItemPtr(const ChartItemPtr &p) : ptr(p.ptr)
|
||||
{
|
||||
}
|
||||
void reset()
|
||||
{
|
||||
ptr = nullptr;
|
||||
}
|
||||
ChartItemPtr &operator=(const ChartItemPtr &p)
|
||||
{
|
||||
ptr = p.ptr;
|
||||
return *this;
|
||||
}
|
||||
operator bool() const
|
||||
{
|
||||
return !!ptr;
|
||||
}
|
||||
bool operator!() const
|
||||
{
|
||||
return !ptr;
|
||||
}
|
||||
T &operator*() const
|
||||
{
|
||||
return *ptr;
|
||||
}
|
||||
T *operator->() const
|
||||
{
|
||||
return ptr;
|
||||
}
|
||||
};
|
||||
|
||||
// In general, we want chart items to be hideable. For example to show/hide
|
||||
// labels on demand. Very sadly, the QSG API is absolutely terrible with
|
||||
// respect to temporarily disabling. Instead of simply having a flag,
|
||||
|
@ -82,6 +128,7 @@ template <typename Node>
|
|||
void HideableQSGNode<Node>::setVisible(bool visible)
|
||||
{
|
||||
hidden = !visible;
|
||||
Node::markDirty(QSGNode::DirtySubtreeBlocked);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue