From 93f86b795d048e5368986dbbdf51e898a841f14c Mon Sep 17 00:00:00 2001 From: bubnikv Date: Wed, 31 Jul 2019 16:36:56 +0200 Subject: [PATCH] asserts for accessing deleted object list nodes. --- src/slic3r/GUI/wxExtensions.cpp | 10 ++++++++++ src/slic3r/GUI/wxExtensions.hpp | 12 +++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/slic3r/GUI/wxExtensions.cpp b/src/slic3r/GUI/wxExtensions.cpp index 9f36eceb9..22eeed77c 100644 --- a/src/slic3r/GUI/wxExtensions.cpp +++ b/src/slic3r/GUI/wxExtensions.cpp @@ -496,6 +496,15 @@ ObjectDataViewModelNode::ObjectDataViewModelNode(ObjectDataViewModelNode* parent set_action_icon(); } +#ifndef NDEBUG +bool ObjectDataViewModelNode::valid() +{ + // Verify that the object was not deleted yet. + assert(m_idx >= -1); + return m_idx >= -1; +} +#endif /* NDEBUG */ + void ObjectDataViewModelNode::set_action_icon() { m_action_icon_name = m_type & itObject ? "advanced_plus" : @@ -1417,6 +1426,7 @@ wxDataViewItem ObjectDataViewModel::GetParent(const wxDataViewItem &item) const return wxDataViewItem(0); ObjectDataViewModelNode *node = (ObjectDataViewModelNode*)item.GetID(); + assert(node != nullptr && node->valid()); // objects nodes has no parent too if (node->m_type == itObject) diff --git a/src/slic3r/GUI/wxExtensions.hpp b/src/slic3r/GUI/wxExtensions.hpp index d7d5fcac2..cbf1f6dfa 100644 --- a/src/slic3r/GUI/wxExtensions.hpp +++ b/src/slic3r/GUI/wxExtensions.hpp @@ -158,7 +158,7 @@ DECLARE_VARIANT_OBJECT(DataViewBitmapText) // ---------------------------------------------------------------------------- -// ObjectDataViewModelNode: a node inside PrusaObjectDataViewModel +// ObjectDataViewModelNode: a node inside ObjectDataViewModel // ---------------------------------------------------------------------------- enum ItemType { @@ -251,6 +251,10 @@ public: ObjectDataViewModelNode *child = m_children[i]; delete child; } +#ifndef NDEBUG + // Indicate that the object was deleted. + m_idx = -2; +#endif /* NDEBUG */ } bool IsContainer() const @@ -260,6 +264,7 @@ public: ObjectDataViewModelNode* GetParent() { + assert(m_parent == nullptr || m_parent->valid()); return m_parent; } MyObjectTreeModelNodePtrArray& GetChildren() @@ -346,6 +351,11 @@ public: bool update_settings_digest(const std::vector& categories); int volume_type() const { return int(m_volume_type); } void msw_rescale(); + +#ifndef NDEBUG + bool valid(); +#endif /* NDEBUG */ + private: friend class ObjectDataViewModel; };