diff options
author | David Tardon <dtardon@redhat.com> | 2017-12-27 15:32:56 +0100 |
---|---|---|
committer | David Tardon <dtardon@redhat.com> | 2017-12-27 15:47:04 +0100 |
commit | 1004d5a21a121bde7ca89d0e18968512fc12137e (patch) | |
tree | ee2a6269bd16d2144c3c6db9c1c077c93dcf7820 | |
parent | 6990552c358226fdcb7c714a0c4e00b8b8124df7 (diff) |
never call shared_from_this on not fully init-ed object
Fixes regression since commit bbe7f806b95ef427153ba18bff80e674b1704ae5
"replace dumb pointers by smart ones".
Change-Id: Ie0dd277bc55347bb1ae5a59ccbeaffaa5ce6772a
-rw-r--r-- | src/lib/MSPUBCollector.cpp | 6 | ||||
-rw-r--r-- | src/lib/ShapeGroupElement.cpp | 25 | ||||
-rw-r--r-- | src/lib/ShapeGroupElement.h | 13 |
3 files changed, 18 insertions, 26 deletions
diff --git a/src/lib/MSPUBCollector.cpp b/src/lib/MSPUBCollector.cpp index 65e432c..718feba 100644 --- a/src/lib/MSPUBCollector.cpp +++ b/src/lib/MSPUBCollector.cpp @@ -439,7 +439,7 @@ void MSPUBCollector::setShapeClipPath(unsigned seqNum, const std::vector<Vertex> void MSPUBCollector::beginGroup() { - auto tmp = std::make_shared<ShapeGroupElement>(m_currentShapeGroup.get()); + auto tmp = ShapeGroupElement::create(m_currentShapeGroup); if (!m_currentShapeGroup) { m_topLevelShapes.push_back(tmp); @@ -455,7 +455,7 @@ bool MSPUBCollector::endGroup() } auto parent = m_currentShapeGroup->getParent(); if (parent) - m_currentShapeGroup = parent->shared_from_this(); + m_currentShapeGroup = parent; return true; } @@ -497,7 +497,7 @@ bool MSPUBCollector::setCurrentGroupSeqNum(unsigned seqNum) void MSPUBCollector::setShapeOrder(unsigned seqNum) { - auto tmp = std::make_shared<ShapeGroupElement>(m_currentShapeGroup.get(), seqNum); + auto tmp = ShapeGroupElement::create(m_currentShapeGroup, seqNum); if (!m_currentShapeGroup) { m_topLevelShapes.push_back(tmp); diff --git a/src/lib/ShapeGroupElement.cpp b/src/lib/ShapeGroupElement.cpp index c61d412..6dcead8 100644 --- a/src/lib/ShapeGroupElement.cpp +++ b/src/lib/ShapeGroupElement.cpp @@ -12,24 +12,20 @@ namespace libmspub { -ShapeGroupElement::ShapeGroupElement(ShapeGroupElement *parent) : m_shapeInfo(), m_parent(parent), m_children(), m_seqNum(0), m_transform() +ShapeGroupElement::ShapeGroupElement(const std::shared_ptr<ShapeGroupElement> &parent, unsigned seqNum) : m_shapeInfo(), m_parent(parent), m_children(), m_seqNum(seqNum), m_transform() { - if (m_parent) - { - m_parent->m_children.push_back(shared_from_this()); - } } ShapeGroupElement::~ShapeGroupElement() { } -ShapeGroupElement::ShapeGroupElement(ShapeGroupElement *parent, unsigned seqNum) : m_shapeInfo(), m_parent(parent), m_children(), m_seqNum(seqNum), m_transform() +std::shared_ptr<ShapeGroupElement> ShapeGroupElement::create(const std::shared_ptr<ShapeGroupElement> &parent, unsigned seqNum) { - if (m_parent) - { - m_parent->m_children.push_back(shared_from_this()); - } + auto that = std::shared_ptr<ShapeGroupElement>(new ShapeGroupElement(parent, seqNum)); + if (parent) + parent->m_children.push_back(that); + return that; } void ShapeGroupElement::setShapeInfo(const ShapeInfo &shapeInfo) @@ -89,14 +85,9 @@ bool ShapeGroupElement::isGroup() const return !m_children.empty(); } -ShapeGroupElement *ShapeGroupElement::getParent() -{ - return m_parent; -} - -const ShapeGroupElement *ShapeGroupElement::getParent() const +std::shared_ptr<ShapeGroupElement> ShapeGroupElement::getParent() const { - return m_parent; + return m_parent.lock(); } void ShapeGroupElement::setSeqNum(unsigned seqNum) diff --git a/src/lib/ShapeGroupElement.h b/src/lib/ShapeGroupElement.h index ef7d175..a51fedc 100644 --- a/src/lib/ShapeGroupElement.h +++ b/src/lib/ShapeGroupElement.h @@ -19,19 +19,21 @@ namespace libmspub { -class ShapeGroupElement : public std::enable_shared_from_this<ShapeGroupElement> +class ShapeGroupElement { boost::optional<ShapeInfo> m_shapeInfo; - ShapeGroupElement *m_parent; + std::weak_ptr<ShapeGroupElement> m_parent; std::vector<std::shared_ptr<ShapeGroupElement>> m_children; unsigned m_seqNum; ShapeGroupElement &operator=(const ShapeGroupElement &); //not implemented ShapeGroupElement(const ShapeGroupElement &); //not implemented VectorTransformation2D m_transform; + ShapeGroupElement(const std::shared_ptr<ShapeGroupElement> &parent, unsigned seqNum); + public: - ShapeGroupElement(ShapeGroupElement *parent); - ShapeGroupElement(ShapeGroupElement *parent, unsigned seqNum); ~ShapeGroupElement(); + static std::shared_ptr<ShapeGroupElement> create(const std::shared_ptr<ShapeGroupElement> &parent, unsigned seqNum = 0); + void setShapeInfo(const ShapeInfo &shapeInfo); void setup(std::function<void(ShapeGroupElement &self)> visitor); void visit(std::function< @@ -42,8 +44,7 @@ public: std::function<void(void)> (const ShapeInfo &info, const Coordinate &relativeTo, const VectorTransformation2D &foldedTransform, bool isGroup, const VectorTransformation2D &thisTransform)> visitor) const; bool isGroup() const; - ShapeGroupElement *getParent(); - const ShapeGroupElement *getParent() const; + std::shared_ptr<ShapeGroupElement> getParent() const; void setSeqNum(unsigned seqNum); void setTransform(const VectorTransformation2D &transform); unsigned getSeqNum() const; |